Skip to content

Commit

Permalink
Fixed similarity fetching for Weaviate hybrid searches (run-llama#9033)
Browse files Browse the repository at this point in the history
  • Loading branch information
pocketcolin authored Nov 21, 2023
1 parent da90c1c commit 9e006ca
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions llama_index/vector_stores/weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,12 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
}
query_builder = query_builder.with_where(filter_with_node_ids)

query_builder = query_builder.with_additional(["id", "vector", "distance"])
query_builder = query_builder.with_additional(
["id", "vector", "distance", "score"]
)

vector = query.query_embedding
similarity_key = "distance"
if query.mode == VectorStoreQueryMode.DEFAULT:
logger.debug("Using vector search")
if vector is not None:
Expand All @@ -262,6 +265,7 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
)
elif query.mode == VectorStoreQueryMode.HYBRID:
logger.debug(f"Using hybrid search with alpha {query.alpha}")
similarity_key = "score"
query_builder = query_builder.with_hybrid(
query=query.query_str,
alpha=query.alpha,
Expand All @@ -284,7 +288,7 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
parsed_result = parse_get_response(query_result)
entries = parsed_result[self.index_name]

similarities = [get_node_similarity(entry) for entry in entries]
similarities = [get_node_similarity(entry, similarity_key) for entry in entries]
nodes = [to_node(entry, text_key=self.text_key) for entry in entries]

nodes = nodes[: query.similarity_top_k]
Expand Down

0 comments on commit 9e006ca

Please sign in to comment.