mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 07:09:31 +00:00
Avoid re-computation of embedding in weaviate similarity search (#8284)
--------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
01a9b06400
commit
e5dba8978a
@ -345,9 +345,9 @@ class Weaviate(VectorStore):
|
||||
content["certainty"] = kwargs.get("search_distance")
|
||||
query_obj = self._client.query.get(self._index_name, self._query_attrs)
|
||||
|
||||
embedded_query = self._embedding.embed_query(query)
|
||||
if not self._by_text:
|
||||
embedding = self._embedding.embed_query(query)
|
||||
vector = {"vector": embedding}
|
||||
vector = {"vector": embedded_query}
|
||||
result = (
|
||||
query_obj.with_near_vector(vector)
|
||||
.with_limit(k)
|
||||
@ -368,9 +368,7 @@ class Weaviate(VectorStore):
|
||||
docs_and_scores = []
|
||||
for res in result["data"]["Get"][self._index_name]:
|
||||
text = res.pop(self._text_key)
|
||||
score = np.dot(
|
||||
res["_additional"]["vector"], self._embedding.embed_query(query)
|
||||
)
|
||||
score = np.dot(res["_additional"]["vector"], embedded_query)
|
||||
docs_and_scores.append((Document(page_content=text, metadata=res), score))
|
||||
return docs_and_scores
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user