File size: 642 Bytes
1762587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# with open("local_data.txt","r") as f:
#
#     data =f.read()
# # for x in data:
# #     print(x)
# with open("data.txt","+a") as d:
#     for x in data.split("."):
#         d.write(str(x)+".")
import faiss
import numpy as np
import google.generativeai as genai
from sentence_transformers import SentenceTransformer

with open("data.txt", "r", encoding="utf-8") as f:
    snippets = [line.strip() for line in f if line.strip()]


embed_model = SentenceTransformer("all-MiniLM-L6-v2")
embeddings = embed_model.encode(snippets)
index = faiss.IndexFlatL2(embeddings.shape[1])
index.add(np.array(embeddings))

print(index)