From d0552acb902aab4173ab124552e937c1f60822c8 Mon Sep 17 00:00:00 2001 From: Hazem Khairy Date: Sun, 24 Mar 2024 12:07:52 +0200 Subject: [PATCH 1/2] fix(vectorstores.py): fetch embedding for the `near_vector` method the near_vector method accepts a parameter called "near_vector", for which the method will perform vector search to get the nearest vector(s). We should get the vector using the embedding object, just as we did in the `hybrid` search method, 4 lines above it. --- langchain_weaviate/vectorstores.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/langchain_weaviate/vectorstores.py b/langchain_weaviate/vectorstores.py index a55997e..1d12bed 100644 --- a/langchain_weaviate/vectorstores.py +++ b/langchain_weaviate/vectorstores.py @@ -255,7 +255,12 @@ def _perform_search( query=query, vector=embedding, limit=k, **kwargs ) elif search_method == "near_vector": - result = collection.query.near_vector(limit=k, **kwargs) + embedding = self._embedding.embed_query(query) + result = collection.query.near_vector( + near_vector = embedding, + limit=k, + **kwargs + ) else: raise ValueError(f"Invalid search method: {search_method}") except weaviate.exceptions.WeaviateQueryException as e: From 2031cc5d64d6f30b4da35531a19b54817e931c11 Mon Sep 17 00:00:00 2001 From: hsm207 Date: Mon, 25 Mar 2024 09:28:51 +0000 Subject: [PATCH 2/2] reformat code Signed-off-by: hsm207 --- langchain_weaviate/vectorstores.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/langchain_weaviate/vectorstores.py b/langchain_weaviate/vectorstores.py index 1d12bed..d2ac205 100644 --- a/langchain_weaviate/vectorstores.py +++ b/langchain_weaviate/vectorstores.py @@ -257,9 +257,7 @@ def _perform_search( elif search_method == "near_vector": embedding = self._embedding.embed_query(query) result = collection.query.near_vector( - near_vector = embedding, - limit=k, - **kwargs + near_vector=embedding, limit=k, **kwargs ) else: raise ValueError(f"Invalid search method: {search_method}")