Skip to content

Conversation

codefromthecrypt
Copy link
Contributor

Impact

This PR aligns openai with the specification changes around embeddings in #2162

Spec changes from 2162

  • Consistent span name: "CreateEmbeddings"
  • Standardized attribute structure: embedding.embeddings.N.embedding.{text|vector}
  • Unified invocation parameter tracking: embedding.invocation_parameters
  • Proper llm.system attribute for provider identification

Code improvements:

  • Full batch embedding support with indexed attributes
  • Separated invocation parameters from input data
  • Improved handling of token IDs vs text inputs

@codefromthecrypt codefromthecrypt requested a review from a team as a code owner September 17, 2025 20:26
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 17, 2025
cursor[bot]

This comment was marked as outdated.

Signed-off-by: Adrian Cole <[email protected]>
Signed-off-by: Adrian Cole <[email protected]>
Comment on lines +305 to +307
# Use consistent span names: "CreateEmbeddings" for embeddings, class name for others
if cast_to is self._openai.types.CreateEmbeddingResponse:
span_name = "CreateEmbeddings"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my understanding here - what does the consistent name buy us rather than maybe naming based on function name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backends typically index the span name field for query and sometimes people do aggregates/auto-complete on the span name. For example, zipkin does auto-complete on span name, but not arbitrary attributes. Some tools dereive metrics from spans and need to aggregate on something, typically that's a span name. So, if something that is in a spec leaves the span name out, it ends up unable to be usable for things like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's an oldie example of this, which is subverted when span names are subtly different for the same operation https://github.com/openzipkin/zipkin-api/blob/master/zipkin2-api.yaml#L44

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I mainly ask because I tend to face a fair amount of pressure to cram things like agent operations in names because there's a need for operators to groc the control flow.

With embedding's generation, though I think this makes a lot of sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I don't think agent ops are commodity yet maybe not for a long while. Wont go trying to normalize those ;)

Comment on lines -40 to -44
try:
_NUMPY: Optional[ModuleType] = import_module("numpy")
except ImportError:
_NUMPY = None

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't remember why this was needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originally it was doing this

                vector = _NUMPY.frombuffer(base64.b64decode(_vector), dtype="float32").tolist()

but we have test cases to prove we can get the vectors at the moment without it. If we need to re-introduce it we probably should with a failing test

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 18, 2025
# openai.types.completion_create_params.CompletionCreateParamsBase
# See https://github.com/openai/openai-python/blob/f1c7d714914e3321ca2e72839fe2d132a8646e7f/src/openai/types/completion_create_params.py#L11 # noqa: E501
"""
Extract attributes from parameters for the LEGACY completions API.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a rewording of the comments which I think better explains the prompt union weirdness

@codefromthecrypt
Copy link
Contributor Author

gonna be away this weekend, so lemme know if there's anything else to do here. regardless, I'll chase up the others next week.

@axiomofjoy axiomofjoy merged commit df5b9d5 into Arize-ai:main Sep 22, 2025
16 checks passed
@github-actions github-actions bot mentioned this pull request Sep 19, 2025
@codefromthecrypt
Copy link
Contributor Author

thanks, put to action here! envoyproxy/ai-gateway#1232

@codefromthecrypt codefromthecrypt deleted the openai-embeddings branch September 25, 2025 05:48
codefromthecrypt added a commit to codefromthecrypt/openinference that referenced this pull request Sep 28, 2025
This PR aligns litellm with the specification changes around embeddings in Arize-ai#2162

**Spec changes from 2162**
- Consistent span name: `"CreateEmbeddings"`
- Standardized attribute structure: `embedding.embeddings.N.embedding.{text|vector}`
- Unified invocation parameter tracking: `embedding.invocation_parameters`
- Proper `llm.system` attribute for provider identification

**Code improvements:**
- Full batch embedding support with indexed attributes
- Separated invocation parameters from input data
- Improved handling of token IDs vs text inputs
- Vectors stored as tuples instead of JSON strings

This is the same as Arize-ai#2210, except litellm.

Signed-off-by: Adrian Cole <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants