File size: 690 Bytes
87188d3
78f2fc1
 
 
 
 
545f3e4
 
75cb8fa
87188d3
 
75cb8fa
87188d3
78f2fc1
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from datasets import load_dataset
from sentence_transformers import SentenceTransformer
import faiss
import numpy as np


# Load a small subset (10,000 rows)
dataset = load_dataset("wiki40b", "en", split="train[:10000]")

# Extract only text
docs = [d["text"] for d in dataset]

print("Loaded dataset with", len(docs), "documents.")

# Load embedding model
embed_model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")

# Convert texts to embeddings
embeddings = embed_model.encode(docs, show_progress_bar=True)

# Store in FAISS index
dimension = embeddings.shape[1]
index = faiss.IndexFlatL2(dimension)
index.add(np.array(embeddings))

print("Stored embeddings in FAISS!")