-
Couldn't load subscription status.
- Fork 148
feat(litellm): align embedding instrumentation with pending spec #2238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(litellm): align embedding instrumentation with pending spec #2238
Conversation
|
so this is the same as #2210, and a FAQ might be why return an indexed list? The reason is that if you have a mixed batch request, you'll get multiple embedding vectors back, index correlated with the input text. one example recorded from the openai instrumentation is this one https://github.com/envoyproxy/ai-gateway/blob/main/tests/internal/testopeninference/spans/embeddings-mixed-batch.json |
python/instrumentation/openinference-instrumentation-litellm/tests/test_batch_embedding.py
Outdated
Show resolved
Hide resolved
.../openinference-instrumentation-litellm/src/openinference/instrumentation/litellm/__init__.py
Outdated
Show resolved
Hide resolved
c0c6750 to
dc87863
Compare
|
@axiomofjoy I updated this PR including the specs along with your rationale about why embeddings spans should have no system/provider attributes. If I got anything wrong, lemme know and I'll bump it! |
Aligns embedding spans with semantic conventions by removing LLM-specific attributes that don't apply to embedding operations and standardizing embedding data structure:
- Removes llm.system and llm.provider from embedding spans (LLM spans unchanged)
- Adds EMBEDDING_INVOCATION_PARAMETERS constant to semantic conventions
- Adds OPENINFERENCE_HIDE_EMBEDDINGS_VECTORS environment variable
- Adds OPENINFERENCE_HIDE_EMBEDDINGS_TEXT environment variable (new functionality)
- Deprecates OPENINFERENCE_HIDE_EMBEDDING_VECTORS (use OPENINFERENCE_HIDE_EMBEDDINGS_VECTORS)
- Updates spec documentation with rationale for attribute exclusions
- Fixes security flaw: api_key excluded from embedding.invocation_parameters
**Key benefits:**
- Clearer semantic conventions: embedding.model_name is sufficient for model identification
- Avoids ambiguity: llm.system definition unclear when applied to embeddings
- Consistent with established patterns: embedding spans use embedding.* prefix exclusively
- Backwards compatible: deprecated hide_embedding_vectors continues to work
**Breaking changes:**
**openinference-instrumentation-openai:**
- `llm.system` attribute removed from embedding spans
- `llm.provider` attribute removed from embedding spans
**openinference-instrumentation-litellm:**
- Attribute names change from `embedding.text` → `embedding.embeddings.{i}.embedding.text`
- Attribute names change from `embedding.vector` → `embedding.embeddings.{i}.embedding.vector`
- `embedding.vector` now captures all embeddings (not just first) as tuples (not JSON strings)
**openinference-instrumentation (TraceConfig):**
- `hide_embedding_vectors` behavior changed: now returns `"__REDACTED__"` instead of removing attribute (None)
- This aligns with documented spec behavior for redacted content
**Deprecations:**
**openinference-instrumentation (TraceConfig):**
- `OPENINFERENCE_HIDE_EMBEDDING_VECTORS` deprecated → use `OPENINFERENCE_HIDE_EMBEDDINGS_VECTORS`
- `hide_embedding_vectors` deprecated → use `hide_embeddings_vectors`
- Both old and new continue to work via OR logic for backwards compatibility
Signed-off-by: Adrian Cole <adrian@tetrate.io>
dc87863 to
b9dc097
Compare
|
#2295 for the unrelated inspector test failures |
| ) -> Iterator[None]: | ||
| LiteLLMInstrumentor().instrument(tracer_provider=tracer_provider) | ||
| yield | ||
| LiteLLMInstrumentor().uninstrument() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this pattern causing an issue?
| ## Attributes Not Used in Embedding Spans | ||
|
|
||
| The following attributes that are used in LLM spans are **not applicable** to embedding spans: | ||
|
|
||
| - `llm.system`: Not used for embedding spans | ||
| - `llm.provider`: Not used for embedding spans | ||
|
|
||
| ### Rationale | ||
|
|
||
| The `llm.system` attribute is defined as "the AI product as identified by the client or server instrumentation." While this definition has been reserved for API providers in LLM spans (e.g., "openai", "anthropic"), it is ambiguous when applied to embedding operations. | ||
|
|
||
| In terms of conceptualization, `llm.system` describes the shape of the API, while `llm.provider` describes the owner of the physical hardware that runs those APIs. For observability products like Arize and Phoenix, these conventions are primarily consumed in playground features, allowing re-invocation of LLM calls. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a stab at this. I'm not sure we need to proscribe using llm.system and llm.provider for embedding spans. Only that we've never used these attributes to describe a client interface like litellm before. In the case of the OpenAI SDK, I think it could make sense to set them. It might make less sense to set them if we don't know the specific API being hit, as is the case for LiteLLM.
Let me chat with @RogerHYang to see if he has the same understanding.
Aligns embedding spans with semantic conventions by removing LLM-specific attributes that don't apply to embedding operations and standardizing embedding data structure:
Benefits:
Breaking changes:
openinference-instrumentation-openai:
llm.systemattribute removed from embedding spansllm.providerattribute removed from embedding spansopeninference-instrumentation-litellm:
embedding.text→embedding.embeddings.{i}.embedding.textembedding.vector→embedding.embeddings.{i}.embedding.vectorembedding.vectornow captures all embeddings (not just first) as tuples (not JSON strings)openinference-instrumentation (TraceConfig):
hide_embedding_vectorsbehavior changed: now returns"__REDACTED__"instead of removing attribute (None)Deprecations:
openinference-instrumentation (TraceConfig):
OPENINFERENCE_HIDE_EMBEDDING_VECTORSdeprecated → useOPENINFERENCE_HIDE_EMBEDDINGS_VECTORShide_embedding_vectorsdeprecated → usehide_embeddings_vectorsNote
Standardizes embedding spans across SDKs: use CreateEmbeddings, embed invocation params and per-item text/vector, drop LLM system/provider for embeddings, and add new embedding redaction config; updates specs and tests accordingly.
SpanAttributes.EMBEDDING_INVOCATION_PARAMETERS; update docs to use span nameCreateEmbeddings, record per-itemembedding.embeddings.{i}.embedding.text/vector, and clarify nollm.system/providerfor embeddings.OPENINFERENCE_HIDE_EMBEDDINGS_VECTORS(deprecatesOPENINFERENCE_HIDE_EMBEDDING_VECTORS) andOPENINFERENCE_HIDE_EMBEDDINGS_TEXT; masking now uses"__REDACTED__".CreateEmbeddings, emitembedding.invocation_parameters, excludellm.system/provider.CreateEmbeddings; capture invocation params; record input texts and all vectors underembedding.embeddings.{i}.*; setembedding.model_namefrom response when present.Written by Cursor Bugbot for commit b9dc097. This will update automatically on new commits. Configure here.