book-broomva-chat / index_creation.py
Broomva's picture
innitial commit
7590ece
raw
history blame
657 Bytes
# %%
from langchain.document_loaders import DirectoryLoader, TextLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import FAISS
# %%
loader = DirectoryLoader(
"../../../docs", glob="./*.md", loader_cls=TextLoader, recursive=True
)
documents = loader.load()
# %%
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
texts = text_splitter.split_documents(documents)
# %%
embedding = OpenAIEmbeddings()
vectordb = FAISS.from_documents(documents=texts, embedding=embedding)
# %%
vectordb.save_local("docs.faiss")
# %%