-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_store.py
More file actions
29 lines (25 loc) · 1.06 KB
/
Copy pathvector_store.py
File metadata and controls
29 lines (25 loc) · 1.06 KB
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
29
from langchain_chroma import Chroma
from langchain_huggingface import HuggingFaceEmbeddings
def create_vector_store(documents, persist_directory="./chroma_db"):
embeddings = HuggingFaceEmbeddings(
model_name="./local_bge_model", # Use the locally saved BGE model
model_kwargs={"device": "cpu"}, # Use 'cuda' if you have a GPU
encode_kwargs={"normalize_embeddings": True}, # Crucial for BGE accuracy
)
vector_store = Chroma.from_documents(
documents=documents,
embedding=embeddings,
persist_directory=persist_directory,
)
return vector_store
def load_vector_store(persist_directory="./chroma_db"):
embeddings = HuggingFaceEmbeddings(
model_name="./local_bge_model", # Use the locally saved BGE model
model_kwargs={"device": "cpu"}, # Use 'cuda' if you have a GPU
encode_kwargs={"normalize_embeddings": True}, # Crucial for BGE accuracy
)
vector_store = Chroma(
persist_directory=persist_directory,
embedding_function=embeddings,
)
return vector_store