mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-06 21:20:33 +00:00
feat: implements similarity_search_by_vector on Weaviate (#2522)
This PR implements `similarity_search_by_vector` in the Weaviate vectorstore.
This commit is contained in:
parent
5c64b86ba3
commit
0316900d2f
@ -89,6 +89,19 @@ class Weaviate(VectorStore):
|
|||||||
docs.append(Document(page_content=text, metadata=res))
|
docs.append(Document(page_content=text, metadata=res))
|
||||||
return docs
|
return docs
|
||||||
|
|
||||||
|
def similarity_search_by_vector(
|
||||||
|
self, embedding: List[float], k: int = 4, **kwargs: Any
|
||||||
|
) -> List[Document]:
|
||||||
|
"""Look up similar documents by embedding vector in Weaviate."""
|
||||||
|
vector = {"vector": embedding}
|
||||||
|
query_obj = self._client.query.get(self._index_name, self._query_attrs)
|
||||||
|
result = query_obj.with_near_vector(vector).with_limit(k).do()
|
||||||
|
docs = []
|
||||||
|
for res in result["data"]["Get"][self._index_name]:
|
||||||
|
text = res.pop(self._text_key)
|
||||||
|
docs.append(Document(page_content=text, metadata=res))
|
||||||
|
return docs
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_texts(
|
def from_texts(
|
||||||
cls,
|
cls,
|
||||||
|
Loading…
Reference in New Issue
Block a user