From 1d2c1abb3a55db7b855e9caf8482dbe2f627ba63 Mon Sep 17 00:00:00 2001 From: DrChristoph <95887663+DrChristophFH@users.noreply.github.com> Date: Thu, 12 Dec 2024 07:03:51 +0100 Subject: [PATCH] Add: allow arbitrary output_fields when dynamic field is enabled (#28) - Don't reject specified output fields that do not match the schema fields if the dynamic field is enabled This allows to specify arbitrary metadata fields to be included in the output when building a retriever: ```py retriever = vectorstore.as_retriever( search_type="similarity", search_kwargs={ "k": 8, "ranker_type": "weighted", "ranker_params": { "weights": [ 0.5, # Dense 0.5, # Sparse ], }, "output_fields": [ "source", "section_title", "text", "pk", ], }, ) ``` --- .../langchain_milvus/retrievers/milvus_hybrid_search.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/milvus/langchain_milvus/retrievers/milvus_hybrid_search.py b/libs/milvus/langchain_milvus/retrievers/milvus_hybrid_search.py index b05198f..12152cd 100644 --- a/libs/milvus/langchain_milvus/retrievers/milvus_hybrid_search.py +++ b/libs/milvus/langchain_milvus/retrievers/milvus_hybrid_search.py @@ -96,9 +96,10 @@ def _validate_fields_name(self) -> None: self.text_field in collection_fields ), f"{self.text_field} is not a valid field in the collection." for field in self.output_fields: # type: ignore[union-attr] - assert ( - field in collection_fields - ), f"{field} is not a valid field in the collection." + if not self.collection.schema.enable_dynamic_field: + assert ( + field in collection_fields + ), f"{field} is not a valid field in the collection." def _get_output_fields(self) -> List[str]: if self.output_fields: