From b80e3825a62e1220811cdc35301eac6884cbc654 Mon Sep 17 00:00:00 2001 From: Bagatur <22008038+baskaryan@users.noreply.github.com> Date: Thu, 10 Aug 2023 18:28:55 -0700 Subject: [PATCH] Bagatur/pinecone by vector (#9087) Co-authored-by: joseph --- .../langchain/vectorstores/pinecone.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/langchain/langchain/vectorstores/pinecone.py b/libs/langchain/langchain/vectorstores/pinecone.py index df5b868444..6ecf0b291b 100644 --- a/libs/langchain/langchain/vectorstores/pinecone.py +++ b/libs/langchain/langchain/vectorstores/pinecone.py @@ -142,12 +142,25 @@ class Pinecone(VectorStore): Returns: List of Documents most similar to the query and score for each """ + return self.similarity_search_by_vector_with_score( + self._embed_query(query), k=k, filter=filter, namespace=namespace + ) + + def similarity_search_by_vector_with_score( + self, + embedding: List[float], + *, + k: int = 4, + filter: Optional[dict] = None, + namespace: Optional[str] = None, + ) -> List[Tuple[Document, float]]: + """Return pinecone documents most similar to embedding, along with scores.""" + if namespace is None: namespace = self._namespace - query_obj = self._embed_query(query) docs = [] results = self._index.query( - [query_obj], + [embedding], top_k=k, include_metadata=True, namespace=namespace,