From 52f4ad82164139d214a7d88eacc9bc563a7e41b8 Mon Sep 17 00:00:00 2001 From: Killinsun - Ryota Takeuchi Date: Tue, 30 Jan 2024 12:59:54 +0900 Subject: [PATCH] community: Add new fields in metadata for qdrant vector store (#16608) ## Description The PR is to return the ID and collection name from qdrant client to metadata field in `Document` class. ## Issue The motivation is almost same to [11592](https://github.com/langchain-ai/langchain/issues/11592) Returning ID is useful to update existing records in a vector store, but we cannot know them if we use some retrievers. In order to avoid any conflicts, breaking changes, the new fields in metadata have a prefix `_` ## Dependencies N/A ## Twitter handle @kill_in_sun --- libs/community/langchain_community/vectorstores/qdrant.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/vectorstores/qdrant.py b/libs/community/langchain_community/vectorstores/qdrant.py index ce64d054d1..d64c5e3b80 100644 --- a/libs/community/langchain_community/vectorstores/qdrant.py +++ b/libs/community/langchain_community/vectorstores/qdrant.py @@ -1941,9 +1941,12 @@ class Qdrant(VectorStore): content_payload_key: str, metadata_payload_key: str, ) -> Document: + metadata = scored_point.payload.get(metadata_payload_key) or {} + metadata["_id"] = scored_point.id + metadata["_collection_name"] = scored_point.collection_name return Document( page_content=scored_point.payload.get(content_payload_key), - metadata=scored_point.payload.get(metadata_payload_key) or {}, + metadata=metadata, ) def _build_condition(self, key: str, value: Any) -> List[rest.FieldCondition]: