as-cle-bert commited on
Commit
82c079b
1 Parent(s): e91f361

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +22 -0
utils.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class NeuralSearcher:
2
+ def __init__(self, collection_name, client, model):
3
+ self.collection_name = collection_name
4
+ # Initialize encoder model
5
+ self.model = model
6
+ # initialize Qdrant client
7
+ self.qdrant_client = client
8
+ def search(self, text: str):
9
+ # Convert text query into vector
10
+ vector = self.model.encode(text).tolist()
11
+
12
+ # Use `vector` for search for closest vectors in the collection
13
+ search_result = self.qdrant_client.search(
14
+ collection_name=self.collection_name,
15
+ query_vector=vector,
16
+ query_filter=None, # If you don't want any filters for now
17
+ limit=1, # 5 the most closest results is enough
18
+ )
19
+ # `search_result` contains found vector ids with similarity scores along with the stored payload
20
+ # In this function you are interested in payload only
21
+ payloads = [hit.payload for hit in search_result]
22
+ return payloads["content"]