o
    /iz                     @   s*   d dl mZ d	ddZdd Zdd ZdS )
    )
connectionNc                 C   sR   d}t  }||| ||g | }|d W  d   S 1 s"w   Y  dS )zp
    Sesuai struktur tabel:
      pk
      pk_attachment
      raw_text
      cleaned_text
      created_at
    z
        INSERT INTO attachments_text (pk_attachment, raw_text, cleaned_text)
        VALUES (%s, %s, %s)
        RETURNING pk;
    r   N)r   cursorexecutefetchone)attachment_idraw_textcleaned_textcategory_idtagssqlcurrow r   2/var/www/html/mfile_papteng_new/webapp/db_utils.pyinsert_fulltext   s   	
$r   c              	   C   sz   d}g }t  +}t|D ]\}}t| }||| |||g || d  qW d   |S 1 s6w   Y  |S )z
    Struktur tabel attachments_chunks:
      pk
      pk_attachment
      chunk_index
      chunk_content
      token_count
    z
        INSERT INTO attachments_chunks
            (pk_attachment, chunk_index, chunk_content, token_count)
        VALUES (%s, %s, %s, %s)
        RETURNING pk;
    r   N)r   r   	enumeratelensplitr   appendr   )r   chunksr   idsr   indexchunktoken_countr   r   r   insert_chunks   s   


r   c                 C   s^   d}t  }t| |D ]\}}| }||||g qW d   dS 1 s(w   Y  dS )zv
    Struktur tabel attachments_embeddings:
      pk
      pk_chunk
      embedding vector(1024)
      created_at
    z_
        INSERT INTO attachments_embeddings (pk_chunk, embedding)
        VALUES (%s, %s);
    N)r   r   ziptolistr   )	chunk_ids
embeddingsr   r   cidembemb_listr   r   r   insert_embeddings=   s   	
"r"   )NN)	django.dbr   r   r   r"   r   r   r   r   <module>   s    
