-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingset.py
42 lines (33 loc) · 1.24 KB
/
ingset.py
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
31
32
33
34
35
36
37
38
39
40
41
42
# main.py
import logging
from utils.loaders import DocumentLoader
from utils.text_processing import TextProcessor
from utils.vector_db import VectorDatabase
from config import DATA_PATH, DB_PATH, EMBED_MODEL_NAME
from langchain_community.embeddings import HuggingFaceEmbeddings
from utils.logging_config import setup_logging
import os
setup_logging()
def main():
"""
Main function to create the vector database from documents.
"""
try:
# Initialize the document loader
doc_loader = DocumentLoader(DATA_PATH)
documents = doc_loader.load_documents()
logging.info(f"Processed {len(documents)} pdf files")
# Check if documents are loaded
if not documents:
raise ValueError("No documents loaded. Check your DATA_PATH.")
# Initialize and apply text processor
text_processor = TextProcessor()
texts = text_processor.split_text(documents)
# Initialize and create vector database
embed_model = HuggingFaceEmbeddings(model_name=EMBED_MODEL_NAME)
vector_db = VectorDatabase(DB_PATH, embed_model)
vector_db.create_vector_db(texts)
except Exception as e:
logging.error(f"An error occurred: {e}")
if __name__ == "__main__":
main()