-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpho.py
47 lines (36 loc) · 1.09 KB
/
vpho.py
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
import json
import chromadb
from sentence_transformers import SentenceTransformer
file_path = 'data.json'
with open(file_path, 'r') as file:
data = json.load(file)
model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
def get_embedding(text):
return model.encode(text).tolist()
client = chromadb.Client()
collection = client.create_collection(name="vpho_rag")
idx = 0
for entry in data:
metadata = {
"logs": json.dumps(entry["mails"]),
}
section_text = entry["section"]
embedding = get_embedding(section_text)
print(entry)
collection.add(
ids=[str(idx)],
embeddings=[embedding],
metadatas=[metadata]
)
idx += 1
print("Data inserted into ChromaDB successfully.")
query = "How is the discussion about CXMAHO with Company A going?"
query_embedding = get_embedding(query)
results = collection.query(query_embeddings=[query_embedding], n_results=1)
print("----------------------------------")
print("")
print("")
print(results)
print("")
print("")
print("----------------------------------")