-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector_store_builder.py
28 lines (22 loc) · 1.08 KB
/
vector_store_builder.py
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 langchain_community.document_loaders import DirectoryLoader
from langchain_openai import OpenAIEmbeddings
from langchain_chroma import Chroma
import os
from langchain.text_splitter import TokenTextSplitter
OPENAI_APIKEY = os.environ['OPENAI_APIKEY']
def build_vector_store():
loader = DirectoryLoader('./ccp')
docs = loader.load()
text_splitter = TokenTextSplitter(model_name='gpt-4o',
chunk_size=700,
chunk_overlap=350)
splits = text_splitter.split_documents(docs)
embeddings_model = OpenAIEmbeddings(api_key=OPENAI_APIKEY,
model='text-embedding-3-large',
max_retries=150,
chunk_size=700,
show_progress_bar=False)
vectorstore = Chroma.from_documents(documents=splits,
embedding=embeddings_model,
persist_directory="./kb_chroma_db")
# build_vector_store()