ó
    À‘´jR  ã                  ór   • S r SSKJr  SSKJr  SSKJr  SSKJr  Sr	\" SS9S	 5       r
SS
 jrSS jrSS jrg)aœ  Embedding helper for the ADE RAG playground.

Reuses quber's local `EmbeddingService` (BAAI/bge-large-en-v1.5, 1024 dims),
which runs on GPU when available and falls back to CPU. Both ingest (embed
each chunk) and query (embed the question) go through the same model, so the
vector spaces match.

Local embeddings are used instead of a hosted API so the experiment has no
external embedding dependency or quota.
é    )Úannotations)Ú	lru_cache)ÚList©Úget_embedding_servicei   é   )Úmaxsizec                 ó   • [        SS9$ )NÚlocal)Úproviderr   © ó    Ú8/home/mande/repo/quber/src/quber/playground/embedding.pyÚ_servicer      s   € ô
 !¨'Ñ2Ð2r   c                óŽ   • U (       d  / $ [        5       R                  U SS9nU Vs/ s H  o"R                  5       PM     sn$ s  snf )Né    )Ú
batch_size)r   ÚembedÚtolist)ÚtextsÚarrÚrows      r   Úembed_textsr      s=   € ÞØˆ	Ü
‹*×
Ñ
˜5¨RÐ
Ð
0€CÙ$'Ó(¢C˜S�J‰JŽL¡CÑ(Ð(ùÒ(s   ¦Ac                ó    • [        U /5      S   $ )Nr   )r   )Útexts    r   Úembed_queryr   %   s   € Ü˜�vÓ˜qÑ!Ð!r   c                óp   • SSK Jn  UR                  5       (       a  UR                  X5      $ [	        U5      $ )zÞEmbed a document's chunks: on the GPU worker when this host is set up
to send work there, locally otherwise. The question at query time always
embeds locally; only ingestion, thousands of chunks at once, is worth a
worker.r   )Úgpu)Úquber.playgroundr   Ú
configuredr   r   )Údoc_keyr   r   s      r   Úembed_documentr"   )   s.   € õ
 %à
‡~�~×ÑØ�y‰y˜Ó(Ð(Ü�uÓÐr   N)r   ú	List[str]ÚreturnúList[List[float]])r   Ústrr$   zList[float])r!   r&   r   r#   r$   r%   )Ú__doc__Ú
__future__r   Ú	functoolsr   Útypingr   Úquber.db.embeddingsr   Ú	EMBED_DIMr   r   r   r"   r   r   r   Ú<module>r-      sE   ðñ	õ #å Ý å 5à€	ñ �1Ññ3ó ð3ô)ô"õ	r   