Skip to content

feat:Update Cohere embed endpoints to support flexible input and new parameters #175

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

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

HavenDV
Copy link
Contributor

@HavenDV HavenDV commented Apr 15, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced embedding endpoints to support mixed text and image inputs within a single request.
    • Added options to specify the maximum number of tokens to embed per input and to control truncation behavior.
    • Introduced the ability to set the output embedding dimension for supported models.
  • Documentation

    • Improved descriptions for input content types in the embedding API.

Copy link

coderabbitai bot commented Apr 15, 2025

Walkthrough

The OpenAPI specification for the Cohere API's embedding endpoints has been updated to support more flexible and detailed input structures. The /v1/embed and /v2/embed POST endpoints now accept an inputs array of EmbedInput objects, each of which can contain both text and image data. New parameters max_tokens and output_dimension have been added to control token limits and embedding dimensionality, respectively. Descriptions for the EmbedImage, EmbedText, and EmbedInput schemas have also been enhanced for clarity.

Changes

File(s) Change Summary
src/libs/Cohere/openapi.yaml Expanded /v1/embed and /v2/embed endpoints to accept inputs (array of EmbedInput), max_tokens, and output_dimension. Added and clarified descriptions for EmbedImage, EmbedText, and EmbedInput schemas.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant EmbedModel

    Client->>API: POST /v1/embed or /v2/embed (inputs, max_tokens, output_dimension)
    API->>EmbedModel: Process array of EmbedInput (text/image), apply max_tokens, output_dimension
    EmbedModel-->>API: Embedding results
    API-->>Client: Embedding response
Loading

Possibly related PRs

Poem

In the garden of endpoints, new seeds we sow,
With images and text, our embeddings grow.
Max tokens we set, dimensions we choose,
Flexible inputs—now nothing to lose!
The API hops forward, so clever and spry,
A rabbit’s delight as new features multiply! 🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@HavenDV HavenDV enabled auto-merge April 15, 2025 12:42
@HavenDV HavenDV merged commit 7ec324e into main Apr 15, 2025
3 of 4 checks passed
@HavenDV HavenDV deleted the bot/update-openapi_202504151241 branch April 15, 2025 12:44
@coderabbitai coderabbitai bot changed the title feat:@coderabbitai feat:Update Cohere embed endpoints to support flexible input and new parameters Apr 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/libs/Cohere/openapi.yaml (2)

8016-8020: output_dimension parameter: well-defined, but consider enumerating allowed values.

The output_dimension property is described as only available for embed-v4 and newer models, with allowed values of 256, 512, 1024, and 1536. However, the schema currently only specifies type: integer and a description.

Recommendation:
To improve API documentation and client validation, consider using an enum to explicitly list the allowed values for output_dimension. This will help prevent invalid requests and make the contract clearer for SDK generators.

Example:

output_dimension:
  type: integer
  enum: [256, 512, 1024, 1536]
  description: ...

15271-15275: EmbedInput.content property: description is accurate, but clarify structure for mixed content.

The description for the content property ("An array of objects containing the input data for the model to embed.") is accurate, but could be more explicit about the expected structure, especially for clients unfamiliar with multimodal input.

Recommendation:
Consider clarifying that each item in the array can be either a text or image object, and provide a short example in the description. This will help API consumers understand how to construct mixed-content inputs.

Example addition:

Each item in the array should be an object of type EmbedText or EmbedImage. For example: [{"type": "text", "text": "hello"}, {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}]

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86e3620 and 8320c89.

⛔ Files ignored due to path filters (8)
  • src/libs/Cohere/Generated/Cohere.CohereClient.Embedv2.g.cs is excluded by !**/generated/**
  • src/libs/Cohere/Generated/Cohere.ICohereClient.Embedv2.g.cs is excluded by !**/generated/**
  • src/libs/Cohere/Generated/Cohere.Models.EmbedContent.g.cs is excluded by !**/generated/**
  • src/libs/Cohere/Generated/Cohere.Models.EmbedImage.g.cs is excluded by !**/generated/**
  • src/libs/Cohere/Generated/Cohere.Models.EmbedInput.g.cs is excluded by !**/generated/**
  • src/libs/Cohere/Generated/Cohere.Models.EmbedText.g.cs is excluded by !**/generated/**
  • src/libs/Cohere/Generated/Cohere.Models.Embedv2Request.g.cs is excluded by !**/generated/**
  • src/libs/Cohere/Generated/JsonSerializerContextTypes.g.cs is excluded by !**/generated/**
📒 Files selected for processing (1)
  • src/libs/Cohere/openapi.yaml (4 hunks)
🔇 Additional comments (2)
src/libs/Cohere/openapi.yaml (2)

15255-15255: EmbedImage schema: description addition is clear and helpful.

The addition of the description "Image content of the input." to the EmbedImage schema is clear and improves the documentation.


15360-15360: EmbedText schema: description addition is clear and helpful.

The addition of the description "Text content of the input." to the EmbedText schema is clear and improves the documentation.

Comment on lines +7998 to +8009
inputs:
type: array
items:
$ref: '#/components/schemas/EmbedInput'
description: An array of inputs for the model to embed. Maximum number of inputs per call is `96`. An input can contain a mix of text and image components.
x-fern-audiences:
- public
max_tokens:
type: integer
description: 'The maximum number of tokens to embed per input. If the input text is longer than this, it will be truncated according to the `truncate` parameter.'
x-fern-audiences:
- public
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

New inputs, max_tokens, and output_dimension fields: strong improvement, but clarify interaction with legacy fields.

The addition of the inputs array (of EmbedInput), max_tokens, and output_dimension to the /v2/embed request schema is well-structured and aligns with modern multimodal embedding API design. The descriptions are clear and the types are correct.

However, there is potential for confusion regarding the interaction between the new inputs field and the legacy texts and images fields, which are still present in the schema. It's not clear:

  • Whether inputs can be used together with texts/images, or if they are mutually exclusive.
  • What happens if both are provided—does one take precedence, or is it an error?
  • If inputs is now the preferred way, consider marking texts/images as deprecated or clarifying in the documentation.

Recommendation:
Add explicit documentation (either in the property descriptions or as a top-level note) clarifying the intended usage and precedence of inputs vs. texts/images. If possible, mark texts and images as deprecated for new clients.

Would you like a suggested wording for this clarification, or a diff to mark the legacy fields as deprecated?


Action Required: Clarify Interaction Between New and Legacy Fields

The new addition of the inputs array (containing EmbedInput objects), max_tokens, and output_dimension to the /v2/embed request schema is well structured and clearly described. However, there remains some ambiguity regarding how these new fields interact with the legacy texts and images fields. In particular, it’s not clear:

  • Whether inputs is intended to be used exclusively, or if it can be combined with texts/images.
  • Which field takes precedence if both are provided, or if using them together should trigger an error.
  • If inputs should be promoted as the standard input method, whether the legacy fields ought to be marked as deprecated.

Recommendation:
Update the OpenAPI documentation by adding an explicit note—either as a property description or a top-level comment—detailing the intended usage and precedence. If appropriate, mark texts and images as deprecated for new clients.

Would you like a suggested diff to implement these clarifications?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant