Skip to content

Commit d9ea51d

Browse files
CopilotMte90
andcommitted
Use EmbeddingClient in llama_integration and remove get_embedding_for_text
- Update llama_integration.py to use EmbeddingClient instead of get_embedding_for_text - Create module-level _embedding_client instance in llama_integration.py - Remove unused get_embedding_for_text function from openai.py - All embedding operations now use EmbeddingClient for consistent logging and retry behavior Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent f28a7ef commit d9ea51d

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

ai/llama_integration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
from typing import List
55
from llama_index.core import Document
66

7-
from .openai import get_embedding_for_text
7+
from .openai import EmbeddingClient
88
from utils.logger import get_logger
99

1010
logger = get_logger(__name__)
1111

12+
# Create a module-level embedding client instance
13+
_embedding_client = EmbeddingClient()
14+
1215

1316
def llama_index_retrieve_documents(query: str, database_path: str, top_k: int = 5,
1417
search_func=None, get_chunk_func=None) -> List[Document]:
@@ -28,7 +31,7 @@ def llama_index_retrieve_documents(query: str, database_path: str, top_k: int =
2831
if search_func is None or get_chunk_func is None:
2932
raise ValueError("search_func and get_chunk_func must be provided")
3033

31-
q_emb = get_embedding_for_text(query)
34+
q_emb = _embedding_client.embed_text(query, file_path="<query>", chunk_index=0)
3235
if not q_emb:
3336
return []
3437

ai/openai.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -296,26 +296,6 @@ def embed_multiple(self, chunks: List[str], file_path: str = "<unknown>") -> Lis
296296
return results
297297

298298

299-
def get_embedding_for_text(text: str, model: Optional[str] = None):
300-
"""
301-
Return embedding vector (list[float]) using the new OpenAI client.
302-
Includes rate limiting, retry logic with exponential backoff, and circuit breaker.
303-
model: optional model id; if not provided, uses DEFAULT_EMBEDDING_MODEL from CFG.
304-
"""
305-
model_to_use = model or DEFAULT_EMBEDDING_MODEL
306-
if not model_to_use:
307-
raise RuntimeError("No embedding model configured. Set EMBEDDING_MODEL in .env or pass model argument.")
308-
309-
def _get_embedding():
310-
resp = _client.embeddings.create(model=model_to_use, input=text)
311-
return resp.data[0].embedding
312-
313-
try:
314-
return _retry_with_backoff(_get_embedding)
315-
except Exception as e:
316-
raise RuntimeError(f"Failed to obtain embedding from OpenAI client: {e}") from e
317-
318-
319299
def call_coding_api(prompt: str, model: Optional[str] = None, max_tokens: int = 1024):
320300
"""
321301
Call a generative/coding model via the new OpenAI client.

0 commit comments

Comments
 (0)