-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (43 loc) · 1.12 KB
/
main.py
File metadata and controls
53 lines (43 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Main Code #
# Import Packages
from generate import generate_embedding
from mongo import collection
import env as e
# Get Env Variables
model = e.model
field = e.field
index = e.index
# User Query
query = "Give me objects having year 1903 and rated TV-G or Passed"
# Generate Embedding For Query
query_embedding = generate_embedding(query)
# Print Query Embedding
print(query_embedding)
# Search Collection
results = collection.aggregate(
[
{
"$vectorSearch": {
"queryVector": query_embedding,
"path": field,
"numCandidates": 50, # Number of Candidates
"limit": 50, # Number of Results
"index": index, # Search Index Name
}
}
]
)
# Print User Query
print("\n# User Query #\n")
print(f"Query: {query}")
# Print Embedding Model
if model == "hf":
print("\n# Hugging Face Embedding Model #\n")
else:
print("\n# OpenAI Embedding Model #\n")
# Print Results
for index, document in enumerate(results):
# Print Object Index
print(f' Object-{index}:')
# Print Document
print(document['_id'])