Avoid re-computation of embedding in weaviate similarity search (#8284)

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
pull/8323/head^2
Rohit Gupta 1 year ago committed by GitHub
parent 01a9b06400
commit e5dba8978a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save