Spaces:
Runtime error
Runtime error
class NeuralSearcher: | |
def __init__(self, collection_name, client, model): | |
self.collection_name = collection_name | |
# Initialize encoder model | |
self.model = model | |
# initialize Qdrant client | |
self.qdrant_client = client | |
def search(self, text: str): | |
# Convert text query into vector | |
vector = self.model.encode(text).tolist() | |
# Use `vector` for search for closest vectors in the collection | |
search_result = self.qdrant_client.search( | |
collection_name=self.collection_name, | |
query_vector=vector, | |
query_filter=None, # If you don't want any filters for now | |
limit=1, | |
) | |
# `search_result` contains found vector ids with similarity scores along with the stored payload | |
# In this function you are interested in payload only | |
payloads = [hit.payload for hit in search_result] | |
return payloads[0]["content"] |