Spaces:
Sleeping
Sleeping
remove build_vector_store
Browse files- build_vector_store.py +0 -25
build_vector_store.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
# build_vector_store.py
|
| 2 |
-
import json
|
| 3 |
-
import numpy as np
|
| 4 |
-
from sentence_transformers import SentenceTransformer
|
| 5 |
-
import faiss
|
| 6 |
-
|
| 7 |
-
def load_chunks():
|
| 8 |
-
with open('processed/chunks.json', 'r', encoding='utf-8') as f:
|
| 9 |
-
chunks = json.load(f)
|
| 10 |
-
return chunks
|
| 11 |
-
|
| 12 |
-
if __name__ == '__main__':
|
| 13 |
-
chunks = load_chunks()
|
| 14 |
-
model = SentenceTransformer('all-mpnet-base-v2')
|
| 15 |
-
texts = [chunk['content'] for chunk in chunks]
|
| 16 |
-
embeddings = model.encode(texts, show_progress_bar=True)
|
| 17 |
-
np.save('processed/embeddings.npy', embeddings)
|
| 18 |
-
with open('processed/metadata.json', 'w', encoding='utf-8') as f:
|
| 19 |
-
json.dump(chunks, f, ensure_ascii=False, indent=4)
|
| 20 |
-
dimension = embeddings.shape[1]
|
| 21 |
-
index = faiss.IndexFlatL2(dimension)
|
| 22 |
-
index.add(embeddings)
|
| 23 |
-
faiss.write_index(index, 'processed/faiss_index.idx')
|
| 24 |
-
|
| 25 |
-
#this creates metadata.json but that's the same as the chunks.json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|