File size: 762 Bytes
ee612b6
 
 
 
 
c6b82b8
 
ee612b6
c6b82b8
 
ee612b6
 
 
 
 
 
 
 
c6b82b8
 
 
ee612b6
 
 
 
c6b82b8
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
from datasets import load_dataset
import faiss
from sentence_transformers import SentenceTransformer
import numpy as np

# Load the US-LegalKit dataset
dataset = load_dataset("macadeliccc/US-LegalKit", split="train")

# Extract legal text documents
law_data = [item['text'] for item in dataset if 'text' in item]

# Load embedding model
model = SentenceTransformer("all-MiniLM-L6-v2")

# Generate embeddings
embeddings = model.encode(law_data, convert_to_numpy=True)

# Create FAISS index
dimension = embeddings.shape[1]
index = faiss.IndexFlatL2(dimension)  # L2 Distance Index
index.add(embeddings)  # Add vectors to FAISS index

# Save FAISS index
faiss.write_index(index, "faiss_index.bin")

print("✅ FAISS index saved successfully as 'faiss_index.bin'!")