33 lines
1.6 KiB
Diff
33 lines
1.6 KiB
Diff
# UNDF: UNDF-2026-000001116
|
|
--- a/libs/langchain/langchain_classic/retrievers/multi_vector.py
|
|
+++ b/libs/langchain/langchain_classic/retrievers/multi_vector.py
|
|
@@ -105,9 +105,10 @@ class MultiVectorRetriever(BaseRetriever):
|
|
sub_docs = self.vectorstore.similarity_search(query, **self.search_kwargs)
|
|
|
|
# We do this to maintain the order of the IDs that are returned
|
|
- ids = []
|
|
+ seen_ids: set = set()
|
|
+ ids = []
|
|
for d in sub_docs:
|
|
- if self.id_key in d.metadata and d.metadata[self.id_key] not in ids:
|
|
+ if self.id_key in d.metadata and d.metadata[self.id_key] not in seen_ids:
|
|
+ seen_ids.add(d.metadata[self.id_key])
|
|
ids.append(d.metadata[self.id_key])
|
|
docs = self.docstore.mget(ids)
|
|
return [d for d in docs if d is not None]
|
|
@@ -147,9 +148,10 @@ class MultiVectorRetriever(BaseRetriever):
|
|
sub_docs = await self.vectorstore.asimilarity_search(
|
|
query, **self.search_kwargs
|
|
)
|
|
|
|
# We do this to maintain the order of the IDs that are returned
|
|
- ids = []
|
|
+ seen_ids_async: set = set()
|
|
+ ids = []
|
|
for d in sub_docs:
|
|
- if self.id_key in d.metadata and d.metadata[self.id_key] not in ids:
|
|
+ if self.id_key in d.metadata and d.metadata[self.id_key] not in seen_ids_async:
|
|
+ seen_ids_async.add(d.metadata[self.id_key])
|
|
ids.append(d.metadata[self.id_key])
|
|
docs = await self.docstore.amget(ids)
|
|
return [d for d in docs if d is not None]
|