docs: clarify limitations of weighted-average embedding for long inputs#2570
Open
alobroke wants to merge 2 commits intoopenai:mainfrom
Open
docs: clarify limitations of weighted-average embedding for long inputs#2570alobroke wants to merge 2 commits intoopenai:mainfrom
alobroke wants to merge 2 commits intoopenai:mainfrom
Conversation
…ts OpenAI embeddings are unit-normalized (L2 norm = 1), so weighting chunks by token count does not recover original embedding magnitudes. Added explicit warning callout, updated docstrings for both functions, and added a use-case comparison table recommending truncation for classification tasks. Fixes openai#2549
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.
Summary
Addresses #2549 — clarifies the mathematical limitations of the
weighted-average approach for long-input embeddings.
Problem
OpenAI embedding models return unit-normalized vectors (L2 norm = 1).
This means the original embedding magnitude is discarded before the
user receives it. The notebook previously implied that weighting chunks
by token count produces a sound representation of the full text — but
this is mathematically a heuristic, not a reconstruction.
Changes
len_safe_get_embeddingdocstring with explicit caveatstruncate_text_tokensdocstring recommending it as thepreferred approach for classification tasks
References
Fixes #2549