Skip to content

fix: validate embedding count in indexer to prevent panic#46

Open
echobt wants to merge 1 commit intomainfrom
fix/issue-142
Open

fix: validate embedding count in indexer to prevent panic#46
echobt wants to merge 1 commit intomainfrom
fix/issue-142

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 20, 2026

Description

This PR addresses an issue where the indexer could panic with an "index out of bounds" error if the embedding engine returned fewer embeddings than the number of chunks provided.

Changes

  • Added validation in Indexer::index_directory to ensure the number of returned embeddings matches the number of chunks.
  • Added validation in ServerIndexer::index_directory to ensure the number of returned embeddings matches the number of chunks, both per-batch and for the total count.
  • The indexer now returns a descriptive error instead of panicking if a mismatch occurs.

Reasoning

When the embedding API fails silently or partially (e.g., due to timeouts, memory limits, or network issues), it may return a partial list of embeddings. iterating over the chunks and accessing the embeddings by index without validation led to a panic. This fix ensures the application handles this failure mode gracefully.

Testing

  • Verified that the logic now checks the lengths before access.
  • Existing tests passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant