Add multiple new search types to AzureCosmosDBNoSqlVectorSearch#20871
Open
allenkim0129 wants to merge 4 commits intorun-llama:mainfrom
Open
Add multiple new search types to AzureCosmosDBNoSqlVectorSearch#20871allenkim0129 wants to merge 4 commits intorun-llama:mainfrom
allenkim0129 wants to merge 4 commits intorun-llama:mainfrom
Conversation
Updated to use 'id', instead of 'ref_doc_id'. Also fixed tests.
- VECTOR_SCORE_THRESHOLD - FULL_TEXT_SEARCH - FULL_TEXT_RANKING - HYBRID - HYBRID_SCORE_THRESHOLD - WEIGHTED_HYBRID_SEARCH
…RF re-ranking - Add WEIGHTED_HYBRID_SEARCH enum value to AzureCosmosDBNoSqlVectorSearchType - Accept 'weights' param in _search_query, _construct_search_query, _execute_search_query - Apply position-based weighted RRF re-ranking client-side (CosmosDB SQL does not support weight= inside ORDER BY RANK RRF) - Update _is_full_text_search_type and _is_vector_search_type to include new type - Add unit tests: ORDER BY clause, construct query, is_* helpers - Add integration test: test_query_weighted_hybrid_search - Update README with weighted hybrid search section and usage examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR significantly extends
llama-index-vector-stores-azurecosmosnosqlwith multiple new search types, a fully parameterised query engine, comprehensive test coverage, and an updated README.What changed
base.py— new search engine_querymethod (single hard-coded vector search) with a new_search_querymethod that supports 6 search types via asearch_typekwargParamMappinghelper to produce fully parameterised CosmosDB SQL queries (no string interpolation of user values)pre_filter={"where_clause": ..., "limit_offset_clause": ...}dict is still accepted and mapped to the newwhere/offset_limitkwargs_generate_projection_fields,_generate_limit_clause,_generate_order_by_clause,_generate_order_by_component_with_full_text_rank_filter,_construct_search_query,_execute_search_query,_validate_search_args,_is_vector_search_type,_is_full_text_search_type,_is_vector_search_with_thresholdhelpersutils.py— new helper module (extracted frombase.py)Constants— all field/parameter name literals in one placeParamMapping— builds@param-style parameterised queries; handles projections, vector distance, inline vector literals for ORDER BY RANK contextsAzureCosmosDBNoSqlVectorSearchType— enum for all supported search typesSearch types added
search_typevectorVectorDistance,ORDER BYvector_score_thresholdfull_text_searchFullTextContainsWHERE predicate, no rankingfull_text_rankingORDER BY RANK FullTextScore(...), single or multi-field RRFhybridORDER BY RANK RRF(FullTextScore, VectorDistance)hybrid_score_thresholdweighted_hybrid_searchweight=is not supported in CosmosDB SQL syntax, so weights are applied after results are returned)Query options added
where— raw CosmosDB SQL WHERE predicateoffset_limit—OFFSET x LIMIT ypagination (replaces TOP for hybrid types)projection_mapping— project specific document fields as node metadatareturn_with_vectors— include raw embeddings in resultsfull_text_rank_filter— list of{search_field, search_text}dicts for full-text ranking componentsthreshold— minimum similarity score for*_score_thresholdtypesweights— per-component float list forweighted_hybrid_search(client-side RRF re-ranking)Tests
test_unit.py— 93 unit tests covering all helpers without any DB access:TestParamMapping,TestGenerateProjectionFields,TestGenerateLimitClause,TestGenerateOrderByComponentWithFullTextRankFilter,TestGenerateOrderByClause,TestConstructSearchQuery,TestIsHelpers,TestSearchQueryPreFilterCompattest_azurecosmosnosql.py— 15 integration tests against a live CosmosDB account:test_add_and_delete,test_query,test_query_vector,test_query_vector_with_k,test_query_vector_with_projection_mapping,test_query_vector_with_offset_limit,test_query_vector_with_where_filter,test_query_full_text_search,test_query_full_text_ranking,test_query_full_text_ranking_multiple_fields,test_query_hybrid_with_score_threshold,test_query_hybrid_with_weights,test_query_weighted_hybrid_search,test_cosmos_client_with_host_and_key,test_cosmos_client_with_connection_stringREADME
New Package?
Version Bump?
Did I bump the version in the
pyproject.toml?Type of Change
How Has This Been Tested?
Unit tests (no DB):
pytest tests/test_unit.py→ 93 passedIntegration tests (live CosmosDB):
→ 15 passed
Suggested Checklist
uv run make format; uv run make lintto appease the lint gods