From 4585eaef1b5c26af5ba6f602b145cc3694a76ebb Mon Sep 17 00:00:00 2001 From: Anush Date: Wed, 24 Jul 2024 20:24:33 +0530 Subject: [PATCH] qdrant: Fix vectors_config access (#24606) ## Description Fixes #24558 by accessing `vectors_config` after asserting it to be a dict. --- .../qdrant/langchain_qdrant/qdrant.py | 30 ++++++++++--------- libs/partners/qdrant/pyproject.toml | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libs/partners/qdrant/langchain_qdrant/qdrant.py b/libs/partners/qdrant/langchain_qdrant/qdrant.py index d7b5970be5a..331de264398 100644 --- a/libs/partners/qdrant/langchain_qdrant/qdrant.py +++ b/libs/partners/qdrant/langchain_qdrant/qdrant.py @@ -950,21 +950,9 @@ class QdrantVectorStore(VectorStore): collection_info = client.get_collection(collection_name=collection_name) vector_config = collection_info.config.params.vectors - if isinstance(vector_config, models.VectorParams) and vector_name != "": - # For single/unnamed vector, - # qdrant-client returns a single VectorParams object - - raise QdrantVectorStoreError( - f"Existing Qdrant collection {collection_name} is built " - "with unnamed dense vector. " - f"If you want to reuse it, set `vector_name` to ''(empty string)." - f"If you want to recreate the collection, " - "set `force_recreate` to `True`." - ) - - else: + if isinstance(vector_config, Dict): # vector_config is a Dict[str, VectorParams] - if isinstance(vector_config, dict) and vector_name not in vector_config: + if vector_name not in vector_config: raise QdrantVectorStoreError( f"Existing Qdrant collection {collection_name} does not " f"contain dense vector named {vector_name}. " @@ -977,6 +965,20 @@ class QdrantVectorStore(VectorStore): # Get the VectorParams object for the specified vector_name vector_config = vector_config[vector_name] # type: ignore + else: + # vector_config is an instance of VectorParams + # Case of a collection with single/unnamed vector. + if vector_name != "": + raise QdrantVectorStoreError( + f"Existing Qdrant collection {collection_name} is built " + "with unnamed dense vector. " + f"If you want to reuse it, set `vector_name` to ''(empty string)." + f"If you want to recreate the collection, " + "set `force_recreate` to `True`." + ) + + assert vector_config is not None, "VectorParams is None" + if isinstance(dense_embeddings, Embeddings): vector_size = len(dense_embeddings.embed_documents(["dummy_text"])[0]) elif isinstance(dense_embeddings, list): diff --git a/libs/partners/qdrant/pyproject.toml b/libs/partners/qdrant/pyproject.toml index 2f6b5ab9a06..ff4500e3381 100644 --- a/libs/partners/qdrant/pyproject.toml +++ b/libs/partners/qdrant/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "langchain-qdrant" -version = "0.1.2" +version = "0.1.3" description = "An integration package connecting Qdrant and LangChain" authors = [] readme = "README.md"