Skip to content

Commit a1b3852

Browse files
committed
refactor: improve log messages and simplify embeddings logic
1 parent 0fa6f23 commit a1b3852

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

src/docs2vecs/subcommands/indexer/skills/ada002_embedding_skill.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@ def __init__(self, config: dict, global_config: Config):
1313

1414
def az_ada002_embeddings(self, content: str, chunk_id=None):
1515
self.logger.debug(
16-
f"Requesting embedding for chunk_id={chunk_id}, content_length={len(content)}"
16+
f"Requesting embedding for chunk_id={chunk_id}, content_length={len(content)} chars"
1717
)
1818
embed_model = AzureOpenAIEmbedding(
1919
deployment_name=self._config["deployment_name"],
2020
api_key=self._config["api_key"],
2121
azure_endpoint=self._config["endpoint"],
2222
api_version=self._config["api_version"],
2323
)
24-
try:
25-
embedding = embed_model.get_query_embedding(content)
26-
self.logger.debug(f"Received embedding for chunk_id={chunk_id}")
27-
return embedding
28-
except Exception as e:
29-
self.logger.error(f"Embedding failed for chunk_id={chunk_id}: {e}")
30-
return None
24+
embedding = embed_model.get_query_embedding(content)
25+
self.logger.debug(
26+
f"Successfully received embedding for chunk_id={chunk_id}, embedding_dim={len(embedding) if embedding else 0}"
27+
)
28+
return embedding
3129

3230
def run(self, input: Optional[List[Document]] = None) -> Optional[List[Document]]:
3331
self.logger.info(
@@ -45,11 +43,8 @@ def run(self, input: Optional[List[Document]] = None) -> Optional[List[Document]
4543
self.logger.debug(f"Processing document: {doc.filename}")
4644
for chunk in doc.chunks:
4745
self.logger.debug(f"Creating embedding for chunk: {chunk.chunk_id}")
48-
if not chunk.content:
49-
chunk.embedding = ""
50-
else:
51-
chunk.embedding = self.az_ada002_embeddings(
52-
chunk.content, chunk_id=chunk.chunk_id
53-
)
46+
chunk.embedding = "" if not chunk.content else self.az_ada002_embeddings(
47+
chunk.content, chunk_id=chunk.chunk_id
48+
)
5449

5550
return input

0 commit comments

Comments
 (0)