Skip to content

Cosmos: support for full-text search #35476

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
roji opened this issue Jan 14, 2025 · 0 comments · Fixed by #35868
Closed

Cosmos: support for full-text search #35476

roji opened this issue Jan 14, 2025 · 0 comments · Fixed by #35868

Comments

@roji
Copy link
Member

roji commented Jan 14, 2025

Cosmos has full text support in preview (docs), and we've received a request to enable that from EF.

Implementation-wise, this shouldn't be too different from the work we did for vector search for 9.0 (see #33783, #35074):

  • Allow modeling information for full-text search; this would set up the full-text policy/index when creating a new container.
  • Query translations for the full-text functions (docs).
    • One interesting idea: rather than providiing e.g. EF.Functions. FullTextContains, the user could simply use regular string Contains; if the referenced property is known to have a full-text index (from the model), we would implicitly translate that Contains to FullTextContains. But this needs to be checked (possibly with the Cosmos people): it would mean the user can no longer decide between regular CONTAINS and FullTextContains (is there any reason to use regular CONTAINS on a column which has a full-text index?).
      • This doesn't work, since full-text search does e.g. stemming, and .NET Contains should do bare character search.
    • For FullTextContainsAll and FullTextContainsAny, we can decide to pattern-match the LINQ constructs Where(x => tags.All(t => x.FullTextContains(t))), rather than introducing a direct overload. Though it's simpler - and maybe a bit more discoverable - for us to just provide the exact functions that Cosmos provides.
    • As part of this, translation support for RRF should be done (hybrid search).
@roji roji added this to the 10.0.0 milestone Jan 15, 2025
maumar added a commit that referenced this issue Mar 29, 2025
outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked)
- support for Owned types (adjust model in tests and fix paths) - this also needs to happen for vector search
- add model building support for default language,
- add more tests for hybrid search,
- add more model validation tests for invalid scenarios (index on multiple columns, FTS on non-string etc)
- add xml docs,
- clean up exception messages and put them in a resource file,
- solve the problem of parameterized Skip/Take,

Fixes #35476
Fixes #35853
maumar added a commit that referenced this issue Mar 31, 2025
outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked)
- support for Owned types (adjust model in tests and fix paths) - this also needs to happen for vector search
- add model building support for default language,
- add more tests for hybrid search,
- add more model validation tests for invalid scenarios (index on multiple columns, FTS on non-string etc)
- add xml docs,
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
maumar added a commit that referenced this issue Mar 31, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked)
- support for Owned types (adjust model in tests and fix paths) - this also needs to happen for vector search
- add model building support for default language,
- add more tests for hybrid search,
- add more model validation tests for invalid scenarios (index on multiple columns, FTS on non-string etc)
- add xml docs,
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
maumar added a commit that referenced this issue Apr 1, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked)
- support for Owned types (adjust model in tests and fix paths) - this also needs to happen for vector search
- add model building support for default language,
- add more tests for hybrid search,
- add more model validation tests for invalid scenarios (index on multiple columns, FTS on non-string etc)
- add xml docs,
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
maumar added a commit that referenced this issue Apr 1, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

- add more model validation tests for invalid scenarios (index on multiple columns, FTS on non-string etc)
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 1, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

- add more model validation tests for invalid scenarios (index on multiple columns, FTS on non-string etc)
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 2, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),
- add more model validation tests for invalid scenarios (index on multiple columns, FTS on non-string etc)
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 2, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),
- add more model validation tests for invalid scenarios (index on multiple columns, FTS on non-string etc)
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 2, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 2, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 3, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),
- clean up exception messages and put them in a resource file,

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 3, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 3, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 3, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 5, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 5, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 7, 2025
Fixes #35476
Fixes #35853 (need to fix this one, otherwise vector translator will try to translate full text methods and fail)

Description
This PR enables full-text search queries using EF Core 9 when targeting Azure Cosmos Db. This is one of the flagship new features for Cosmos and the aim here is to help with it's adoption. This is very limited port of the full feature we are adding in EF 10 Preview 4. We are only adding querying capabilities: function stubs for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF as well as logic translating these signatures to built-in Cosmos functions.
No model building or data manipulation - containers need to be created outside EF (using Cosmos SDK or in the Data Explorer).

Customer impact
Customers will be able to use the upcoming full text search capabilities when working with Azure Cosmos Db without the need to upgrade to EF 10 preview.

How found
Partner team ask.

Regression
No

Testing
Extensively tested on EF 10, manual testing on EF9. End-to-end testing is not possible because we can't create containers programmatically (no support for it inside EF Core itself, and the Cosmos SDK which supports it is currently only available in beta, so we can't take dependency on it). Instead, we created containers and data using EF 10, ported all the query tests from EF 10 and ran them using the EF9 bits.

Risk
Low. Code here is purely additive and actually localized to only a handful of places in the code: validation in ApplyOrdering/AppendOrdering, FTS method translator, parameter inliner and sql generator. Feature is marked as experimental and quirks have been added.
maumar added a commit that referenced this issue Apr 9, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 12, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 14, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)
- add model building support for default language (superfluous for now, since only one language is supported),

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 14, 2025
…35909)

* Limited port of #35868

Fixes #35476
Fixes #35853 (need to fix this one, otherwise vector translator will try to translate full text methods and fail)

Description
This PR enables full-text search queries using EF Core 9 when targeting Azure Cosmos Db. This is one of the flagship new features for Cosmos and the aim here is to help with it's adoption. This is very limited port of the full feature we are adding in EF 10 Preview 4. We are only adding querying capabilities: function stubs for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF as well as logic translating these signatures to built-in Cosmos functions.
No model building or data manipulation - containers need to be created outside EF (using Cosmos SDK or in the Data Explorer).

Customer impact
Customers will be able to use the upcoming full text search capabilities when working with Azure Cosmos Db without the need to upgrade to EF 10 preview.

How found
Partner team ask.

Regression
No

Testing
Extensively tested on EF 10, manual testing on EF9. End-to-end testing is not possible because we can't create containers programmatically (no support for it inside EF Core itself, and the Cosmos SDK which supports it is currently only available in beta, so we can't take dependency on it). Instead, we created containers and data using EF 10, ported all the query tests from EF 10 and ran them using the EF9 bits.

Risk
Low. Code here is purely additive and actually localized to only a handful of places in the code: validation in ApplyOrdering/AppendOrdering, FTS method translator, parameter inliner and sql generator. Feature is marked as experimental and quirks have been added.

* fix FTContainsAll/Any for constants,
change TFScore signature to accept params,
fixed SqlFunctionExpression to use the new ctor internally,
added mandatory property overrides for FragmentExpression (vector search)
fixed parameter inliner to not match parameter of type string, but only string[] when processing ContainsAll/Any
maumar added a commit that referenced this issue Apr 15, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.
- Adding model building support for default language on the container level

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
maumar added a commit that referenced this issue Apr 15, 2025
- Adding model building API to configure property as full-text search enabled, as well as setup the index for it,
- Adding model validation (e.g. FTS index not matching FTS property),
- Adding EF.Functions stubs and translations for FullTextContains, FullTextContainsAll, FullTextContainsAny, FullTextScore and RRF (for hybrid),
- Adding logic in SelectExpression to produce ORDER BY RANK when necessary,
- Adding validation when attempting to mix with ORDER BY RANK with regular ORDER BY,
- Rewrite OFFSET/LIMIT from parameter to constant when ORDER BY RANK is present.
- Adding model building support for default language on the container level

Also fixed / added support for vector search on owned types (since it shares logic with FTS) and added some tests.

outstanding work:
- support for FTS Container building using Azure.ResourceManager.CosmosDb (currently blocked on updated package being released)

Fixes #35476
Fixes #35853
Fixes #35867
Fixes #35852
@maumar maumar closed this as completed in 0024b2b Apr 15, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants