Lung-Cancer-AI-Advisor / core /vector_store.py
moazx's picture
Initial commit
2a8faae
raw
history blame
1.26 kB
from . import utils
from .config import logger
def create_vector_store():
# Try to load existing vector store, create if not found
try:
company_documents = utils.create_company_documents()
company_chunks = utils.split_documents(company_documents)
vector_store = utils.create_company_vector_store(company_chunks)
logger.info("Vector store created successfully")
except Exception as e:
logger.error(f"Error creating vector store: {str(e)}")
raise
def load_vector_store() -> Optional[FAISS]:
"""Load existing vector store with proper error handling"""
try:
if Path(VECTOR_STORE_DIR).exists():
vector_store = FAISS.load_local(
str(VECTOR_STORE_DIR),
EMBEDDING_MODEL,
allow_dangerous_deserialization=True
)
logger.info("Successfully loaded existing vector store")
return vector_store
else:
logger.info("No existing vector store found")
logger.info("Creating new vector store...")
create_vector_store()
return None
except Exception as e:
logger.error(f"Failed to load vector store: {e}")
return None