forked from lvendrix/notion-chatbot-public
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathingest.py
More file actions
30 lines (24 loc) · 1.02 KB
/
ingest.py
File metadata and controls
30 lines (24 loc) · 1.02 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
30
import streamlit as st
import openai
from langchain.document_loaders import NotionDirectoryLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import FAISS
# Load OpenAI API key
openai.api_key = st.secrets["OPENAI_API_KEY"]
# Load the notion content located in the notion_content folder
loader = NotionDirectoryLoader("notion_content")
documents = loader.load()
# Split Notion content into smaller chunks
markdown_splitter = RecursiveCharacterTextSplitter(
separators=["#","##", "###", "\n\n","\n","."],
chunk_size=1500,
chunk_overlap=100)
docs = markdown_splitter.split_documents(documents)
# Initialize OpenAI embedding model
embeddings = OpenAIEmbeddings()
# Convert all chunks into vectors embeddings using OpenAI embedding model
# Store all vectors in FAISS index and save locally to 'faiss_index'
db = FAISS.from_documents(docs, embeddings)
db.save_local("faiss_index")
print('Local FAISS index has been successfully saved.')