SergeyO7 commited on
Commit
e3c118a
·
verified ·
1 Parent(s): bd4a39c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -52,20 +52,23 @@ def split_text(documents: list[Document]):
52
 
53
 
54
  def save_to_chroma(chunks: list[Document]):
55
- # Clear out the database first.
56
  if os.path.exists(CHROMA_PATH):
57
  shutil.rmtree(CHROMA_PATH)
58
 
59
- # Create a new DB from the documents.
 
 
 
 
 
 
60
  db = Chroma.from_documents(
61
  chunks,
62
- HuggingFaceEmbeddings(model_name="BAAI/bge-m3"),
63
- cache_folder="model_cache", # Укажите путь для кэша
64
  persist_directory=CHROMA_PATH
65
  )
66
-
67
  print(f"Saved {len(chunks)} chunks to {CHROMA_PATH}.")
68
 
69
-
70
  if __name__ == "__main__":
71
  main()
 
52
 
53
 
54
  def save_to_chroma(chunks: list[Document]):
55
+ # Clear out the database first
56
  if os.path.exists(CHROMA_PATH):
57
  shutil.rmtree(CHROMA_PATH)
58
 
59
+ # Initialize embeddings with cache
60
+ embeddings = HuggingFaceEmbeddings(
61
+ model_name="BAAI/bge-m3",
62
+ cache_folder="model_cache" # Правильное место для кэша
63
+ )
64
+
65
+ # Create Chroma DB
66
  db = Chroma.from_documents(
67
  chunks,
68
+ embeddings, # Используем предварительно созданный объект
 
69
  persist_directory=CHROMA_PATH
70
  )
 
71
  print(f"Saved {len(chunks)} chunks to {CHROMA_PATH}.")
72
 
 
73
  if __name__ == "__main__":
74
  main()