File size: 1,256 Bytes
2a8faae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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