-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
25 lines (19 loc) · 711 Bytes
/
Copy pathmain.py
File metadata and controls
25 lines (19 loc) · 711 Bytes
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
import numpy as np
import faiss
import json
from sentence_transformers import SentenceTransformer
embeddings = np.load("embeddings.npy")
with open("texts.json", "r", encoding = "utf-8") as f:
texts = json.load(f)
dimension = embeddings.shape[1]
index = faiss.IndexFlatL2(dimension)
index.add(embeddings)
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
query = "What is Succession About and studio who created it?"
query_embeddings = model.encode([query]).astype('float32')
k=5
distances, indexes = index.search(query_embeddings, k)
print("Distances:", distances)
print("Indexes:", indexes)
for idex in indexes[0]:
print(f"Text {idex+1}:", texts[idex])