Spaces:
Runtime error
Runtime error
File size: 991 Bytes
82c079b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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, # 5 the most closest results is enough
)
# `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["content"] |