Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
from langchain_community.document_loaders import UnstructuredMarkdownLoader
|
2 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
3 |
-
from
|
4 |
# from langchain_openai import OpenAIEmbeddings
|
5 |
-
from
|
6 |
from langchain_community.vectorstores import Chroma
|
7 |
from dotenv import load_dotenv
|
8 |
import os
|
|
|
9 |
|
10 |
# Load environment variables
|
11 |
load_dotenv()
|
@@ -29,7 +30,8 @@ def load_documents():
|
|
29 |
if not os.path.exists(file_path):
|
30 |
print(f"Error: File {file_path} not found.")
|
31 |
return []
|
32 |
-
loader
|
|
|
33 |
documents = loader.load()
|
34 |
return documents
|
35 |
|
@@ -57,7 +59,9 @@ def save_to_chroma(chunks: list[Document]):
|
|
57 |
|
58 |
# Create a new DB from the documents.
|
59 |
db = Chroma.from_documents(
|
60 |
-
chunks,
|
|
|
|
|
61 |
)
|
62 |
db.persist()
|
63 |
print(f"Saved {len(chunks)} chunks to {CHROMA_PATH}.")
|
|
|
1 |
from langchain_community.document_loaders import UnstructuredMarkdownLoader
|
2 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
3 |
+
from langchain_core.documents import Document # Updated import
|
4 |
# from langchain_openai import OpenAIEmbeddings
|
5 |
+
from langchain_huggingface import HuggingFaceEmbeddings # Updated import
|
6 |
from langchain_community.vectorstores import Chroma
|
7 |
from dotenv import load_dotenv
|
8 |
import os
|
9 |
+
import shutil # Added import
|
10 |
|
11 |
# Load environment variables
|
12 |
load_dotenv()
|
|
|
30 |
if not os.path.exists(file_path):
|
31 |
print(f"Error: File {file_path} not found.")
|
32 |
return []
|
33 |
+
loader
|
34 |
+
= UnstructuredMarkdownLoader(file_path)
|
35 |
documents = loader.load()
|
36 |
return documents
|
37 |
|
|
|
59 |
|
60 |
# Create a new DB from the documents.
|
61 |
db = Chroma.from_documents(
|
62 |
+
chunks,
|
63 |
+
HuggingFaceEmbeddings(model_name="BAAI/bge-small-en-v1.5"),
|
64 |
+
persist_directory=CHROMA_PATH
|
65 |
)
|
66 |
db.persist()
|
67 |
print(f"Saved {len(chunks)} chunks to {CHROMA_PATH}.")
|