fix(common-ai): pre-embed nodes so LlamaIndexEmbeddingOperator returns vectors#68488
Closed
AgentNero-ch wants to merge 1 commit into
Closed
fix(common-ai): pre-embed nodes so LlamaIndexEmbeddingOperator returns vectors#68488AgentNero-ch wants to merge 1 commit into
AgentNero-ch wants to merge 1 commit into
Conversation
…s vectors VectorStoreIndex._get_node_with_embedding() attaches embeddings to *copies* of nodes (via model_copy()), never the originals. The operator was relying on VectorStoreIndex populating node.embedding as a side effect, which always yielded None. Fix: call embed_model.get_text_embedding_batch() on the original nodes before passing them to VectorStoreIndex. The index's internal embed_nodes() skips nodes whose .embedding is already set, so there are no duplicate API calls. Closes apache#68416
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
LlamaIndexEmbeddingOperator.execute()returns chunks with"vector": Nonebecause it relies onVectorStoreIndexto populatenode.embeddingas a side effect. ButVectorStoreIndex._get_node_with_embedding()attaches embeddings to copies of the nodes (viamodel_copy()), never the originals.Fix
Call
embed_model.get_text_embedding_batch()on the original nodes before passing them toVectorStoreIndex. The index's internalembed_nodes()skips nodes whose.embeddingis already set, so there are no duplicate API calls.Why this works
From llama-index-core source (
indices/utils.py):python
def embed_nodes(nodes, embed_model, ...):
for node in nodes:
if node.embedding is not None:
continue # skip already-embedded nodes
...
Verified across llama-index-core v0.10.68 through v0.14.22 — all versions copy nodes internally, so the side-effect assumption has never held.
Testing
Updated unit tests to mock
get_text_embedding_batchinstead of relying onVectorStoreIndexside effects. Added a new test verifying the pre-embed step is called with correct node texts.Closes #68416