Repository: run-llama/llama_index
Pull request: [Issue #17219] MilvusVectorStore Parse "milvus_search_config" out of "vector_store_kwargs"
# Description

Currently, the MilvusVectorStore saves "search_config" used by ALL queries during 'init' and we cannot change it at query runtime. This change allows us to override this default init configuration for uses where we need a different search criteria, like in "range queries". We already have a **kwargs parameter in the "query" function parameters we use to pass milvus specific configuration like the "milvus_scalar_filters", and we could use this to pass in a "milvus_search_config".

Fixes # (issue)
17209

## Type of Change

- [ ] New feature (non-breaking change which adds functionality)


## How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

- [ ] I believe this change is already covered by existing unit tests


## Suggested Checklist:

- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings
- [ ] New and existing unit tests pass locally with my changes


Problem statement:
[Feature Request]: MilvusVectorStore - Add ability to specify search_params to query
### Feature Description

Currently, the MilvusVectorStore stores search_params used by ALL queries at __init__. It would be useful to allow oeverriding this "default" configuration for an individual query for cases like "range queries." We already have a **kwargs parameter in the "query" function we use to pass milvus specific configuration like the "milvus_scalar_filters", and we could use this to pass in a "milvus_search_params".

### Reason

Currently we can only specify the query search_params at MilvusVectorStore init, but this is a setting we may want to be different on each call to the "query" function.

### Value of Feature

It allows us to support dynamic "range queries" without recreating the MilvusVectorStore index every time.

Hints from issue discussion:

Commit message:  MilvusVectorStore Query parses "milvus_search_config" out of "vector_store_kwargs"

Patch to review:
diff --git a/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py b/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py
index bfc30a4ae7..8c976546e7 100644
--- a/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py
+++ b/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py
@@ -619,7 +619,7 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
                 filter=string_expr,
                 limit=query.similarity_top_k,
                 output_fields=output_fields,
-                search_params=self.search_config,
+                search_params=kwargs["milvus_search_config"] if "milvus_search_config" in kwargs else self.search_config,
                 anns_field=self.embedding_field,
             )
             logger.debug(
@@ -684,7 +684,7 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
                 filter=string_expr,
                 limit=prefetch_k0,
                 output_fields=output_fields,
-                search_params=self.search_config,
+                search_params=kwargs["milvus_search_config"] if "milvus_search_config" in kwargs else self.search_config,
                 anns_field=self.embedding_field,
             )
 


Code review comments:
diff_hunk: @@ -619,7 +619,7 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
                 filter=string_expr,
                 limit=query.similarity_top_k,
                 output_fields=output_fields,
-                search_params=self.search_config,
+                search_params=kwargs["milvus_search_config"] if "milvus_search_config" in kwargs else self.search_config,
path: llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py
text: @user1:
You can do `search_params=kwargs.get("milvus_search_config", self.search_config)`

@author:
I haven't looked at other vector db's and how they might handle (or whether they even support) these search parameters Since this was an adjustment only for the MilvusVectorStore I figured it would be in line with the "milvus_scalar_filters" "vector_store_kwargs" key to differentiate it as specifically Milvus.

@author:
> kwargs.get("milvus_search_config", self.search_config)

You are right. I changed it to this to follow the pattern used in the rest of the class.