-
Notifications
You must be signed in to change notification settings - Fork 2
/
Indexer.py
28 lines (27 loc) · 1.06 KB
/
Indexer.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_experimental.text_splitter import SemanticChunker # type: ignore
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_community.document_loaders import DirectoryLoader
from langchain_community.embeddings import OllamaEmbeddings
from langchain_community.vectorstores import Chroma
# Load documents from a PDF file
loader = DirectoryLoader("Data", glob="**/*.pdf")
print("pdf loaded loader")
documents = loader.load()
print(len(documents))
# # Create embeddingsclear
embeddings = OllamaEmbeddings(model="nomic-embed-text", show_progress=True)
# # Create Semantic Text Splitter
# text_splitter = SemanticChunker(embeddings, breakpoint_threshold_type="interquartile")
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=5000,
chunk_overlap=300,
add_start_index=True,
)
# # Split documents into chunks
texts = text_splitter.split_documents(documents)
# # Create vector store
vectorstore = Chroma.from_documents(
documents=texts,
embedding= embeddings,
persist_directory="./db-mawared")
print("vectorstore created")