from .embeddings import get_embeddings_batch ,get_embedding 
from ..chroma .vector_store import insert_documents ,search_documents 

def ingest_documents (text_chunks ,collection_name ="rag_documents",source_file =None ,category =None ):
    embeddings =get_embeddings_batch (text_chunks )

    metadata_list =None 
    if source_file or category :
        metadata_list =[]
        for _ in text_chunks :
            meta ={}
            if source_file :
                meta ["source"]=source_file 
            if category :
                meta ["category"]=category 
            metadata_list .append (meta )

    return insert_documents (text_chunks ,embeddings ,collection_name =collection_name ,metadata_list =metadata_list )

def vector_search (query_text ,collection_name ="rag_documents",num_results =5 ,category =None ):
    query_embedding =get_embedding (query_text )

    filter_metadata =None 
    if category :
        filter_metadata ={"category":category }

    return search_documents (query_embedding ,collection_name =collection_name ,num_results =num_results ,filter_metadata =filter_metadata )
