anl139 commited on
Commit
4f3c8f5
·
verified ·
1 Parent(s): 1f27a13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -75,14 +75,14 @@ data = loader.load()
75
  # (If you find that key fields are getting split, consider implementing a custom splitter.)
76
  from langchain_text_splitters import RecursiveCharacterTextSplitter
77
  text_splitter = RecursiveCharacterTextSplitter(
78
- chunk_size=1250,
79
- chunk_overlap=150,
80
  add_start_index=True
81
  )
82
  def split_document_with_metadata(document):
83
- # Split the document into chunks
84
  chunks = text_splitter.split_text(document.page_content)
85
- # Attach the full metadata to every chunk
86
  return [Document(page_content=chunk, metadata=document.metadata) for chunk in chunks]
87
 
88
  all_splits = []
@@ -94,6 +94,14 @@ for doc in data:
94
 
95
  # Create a Chroma vector store using the document splits.
96
  persist_directory = "./chroma_db"
 
 
 
 
 
 
 
 
97
  vectorstore = Chroma.from_documents(
98
  documents=all_splits,
99
  embedding=OpenAIEmbeddings(),
 
75
  # (If you find that key fields are getting split, consider implementing a custom splitter.)
76
  from langchain_text_splitters import RecursiveCharacterTextSplitter
77
  text_splitter = RecursiveCharacterTextSplitter(
78
+ chunk_size=1500,
79
+ chunk_overlap=100,
80
  add_start_index=True
81
  )
82
  def split_document_with_metadata(document):
83
+ # Split the document text into chunks.
84
  chunks = text_splitter.split_text(document.page_content)
85
+ # Ensure every chunk has the complete original metadata.
86
  return [Document(page_content=chunk, metadata=document.metadata) for chunk in chunks]
87
 
88
  all_splits = []
 
94
 
95
  # Create a Chroma vector store using the document splits.
96
  persist_directory = "./chroma_db"
97
+ if os.path.exists(persist_directory):
98
+ print(f"Clearing existing vector store at {persist_directory}...")
99
+ shutil.rmtree(persist_directory)
100
+
101
+ # -------------------------------
102
+ # Set Up Retrievers
103
+ # -------------------------------
104
+ # Create a Chroma vector store using the document splits.
105
  vectorstore = Chroma.from_documents(
106
  documents=all_splits,
107
  embedding=OpenAIEmbeddings(),