o
    "i	                     @   sV   d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ G dd dZdS )	    N)models)MySQLRepository)QdrantRepository)EmbeddingService)semantic_chunk_by_speaker_turnsc                   @   sL   e Zd ZdededefddZdededed	ee d
ee	 de
fddZdS )IngestionServiceqdrant_repo
mysql_repoemb_servicec                 C   s   || _ || _|| _d S )N)qdrantmysqlemb)selfr   r	   r
    r   K/home/aiteam/pcaa-dev/ai-call-quality-rag/app/services/ingestion_service.py__init__   s   
zIngestionService.__init__	tenant_idcall_idagent_idtags
transcriptreturnc                 C   s  t ||d}|s| j|||d| dS | jdd |D }| jjt|d d g }	t||D ]D\}
}||||
j	s=|rD|
j	pA|
 nd |
j|
j||
j|
jd	}|	tjtt ||d | jj||||
j|
j|
j|
j|
j	pr|d q1| j|	 | j|||t|| t|S )	N)r   turnsr   c                 S   s   g | ]}|j qS r   )text).0cr   r   r   
<listcomp>   s    z0IngestionService.ingest_call.<locals>.<listcomp>)vector_size)	r   r   r   	timestampspeakerr   r   chunk_idchunk_index)idvectorpayload)r   r   r   r!   r    r   r   r   )r   r   save_call_ingestionr   embed_textsr   ensure_collectionlenzipr   	isoformatr   r   r    idxappendqmPointStructstruuiduuid4save_chunk_metadataupsert_chunks)r   r   r   r   r   r   r   chunksvectorspointschunkvecr$   r   r   r   ingest_call   sL   
zIngestionService.ingest_callN)__name__
__module____qualname__r   r   r   r   r/   listdictintr9   r   r   r   r   r      s    .r   )r0   qdrant_client.httpr   r-   !app.repositories.mysql_repositoryr   "app.repositories.qdrant_repositoryr   app.services.embedding_servicer   app.utils.chunkingr   r   r   r   r   r   <module>   s    