feat(openai): add openai embeddings api support (#1345) #1372
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.
Important
Adds support for OpenAI's embeddings API to Langfuse, including synchronous and asynchronous operations, with comprehensive test coverage.
OpenAiDefinition
entries for synchronous and asynchronous embedding operations inlangfuse/openai.py
."OpenAI-embedding"
as default operation name for embeddings.input
parameter for embeddings.dimensions
andencoding_format
."embedding"
.test_openai_embeddings
,test_openai_embeddings_multiple_inputs
, andtest_async_openai_embeddings
intests/test_openai.py
.This description was created by
for b65d602. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
Updated On: 2025-09-18 15:43:55 UTC
This PR adds comprehensive support for OpenAI's embeddings API to the Langfuse integration. The changes span both the core integration logic and test coverage to handle embeddings as a distinct type of operation alongside existing chat completions and text completions.
Core Integration Changes:
The implementation adds two new
OpenAiDefinition
entries for synchronous and asynchronous embedding operations, following the established pattern used for other OpenAI APIs. The wrapper logic has been extended with conditional handling based onresource.type == "embedding"
throughout the codebase to accommodate the different input/output structure of embeddings compared to chat/completion APIs.Key behavioral differences for embeddings include:
"OpenAI-embedding"
as the default operation name instead of"OpenAI-generation"
input
parameter rather thanmessages
orprompt
dimensions
andencoding_format
instead of chat parameters liketemperature
"embedding"
rather than"generation"
Test Coverage:
Three comprehensive test functions validate the integration:
test_openai_embeddings
for basic single-input operations,test_openai_embeddings_multiple_inputs
for batch processing, andtest_async_openai_embeddings
for asynchronous operations. The tests verify proper observation type tracking, input/output handling, usage statistics, and metadata preservation.The implementation maintains backward compatibility with existing functionality while extending the Langfuse integration to cover embeddings, which are essential for vector search, semantic similarity, and RAG applications.
Confidence score: 4/5
langfuse/openai.py