I created a function to get weaviate scores by directly querying with the database:
# Within my custom class
import weaviate
from weaviate.classes.query import MetadataQuery
"""
params:
self - init with Weaviate client
collection_name - name of your collection
question - text based question
query_vector - your question converted to vector with the embed model used
limit - number of docs to retrieve
hybrid_score - also known as alpha in Weaviate to select between bm25 and vector
"""
def get_weaviate_scores(self, collection_name, question, query_vector, limit, hybrid_score):
collection = self.client.collections.get(collection_name)
response = collection.query.hybrid(
query=question,
vector=query_vector,
limit=limit,
alpha=hybrid_score,
return metadata=MetadataQuery(
distance=True,
certainty=True,
score=True,
explain_score=True,
)
)
weaviate_score_list = {}
for obj in response.objects:
# Get your scores here and append to weaviate_score_list
# e.g. weaviate_score_list[file_path] = score
return weaviate_score_list