Skip to content

Python: Add Voyage AI embedding client package - #1

Open
fzowl wants to merge 6 commits into
mainfrom
feat/voyage-ai-embeddings
Open

fzowl wants to merge 6 commits into
mainfrom
feat/voyage-ai-embeddings

Conversation

@fzowl

@fzowl fzowl commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Motivation & Context

Agent Framework has embedding clients for OpenAI, Azure OpenAI, Foundry, Gemini, Bedrock, Ollama, Mistral AI and NVIDIA NIM, but none for Voyage AI. Voyage AI's text embedding models (including the code, finance and law models) are widely used for retrieval, and users who want them with InMemoryCollection and the other vector stores currently have to write their own BaseEmbeddingClient.

Description & Review Guide

Adds an alpha package, agent-framework-voyageai, modelled on agent-framework-mistral and agent-framework-nvidia. It uses the official voyageai SDK, as the Mistral package uses mistralai.

from agent_framework_voyageai import VoyageAIEmbeddingClient

# VOYAGE_API_KEY is read from the environment; the model is always named explicitly.
client = VoyageAIEmbeddingClient(model="voyage-4")
documents = await client.get_embeddings(["Hello, world!"], options={"input_type": "document", "dimensions": 512})
  • What are the major changes?
    • VoyageAIEmbeddingClient and RawVoyageAIEmbeddingClient (with and without the telemetry layer), VoyageAIEmbeddingOptions and VoyageAIEmbeddingSettings (VOYAGE_API_KEY, VOYAGE_EMBEDDING_MODEL, VOYAGE_BASE_URL).
    • VoyageAIContextualizedEmbeddingClient for voyage-context-4 and voyage-context-3, with its own get_contextualized_embeddings method and result type (a vector per chunk, plus the chunk text), because one document yields several vectors and get_embeddings returns one vector per input.
    • Supported models: voyage-4-large, voyage-4, voyage-4-lite, voyage-code-4, voyage-3-large, voyage-3.5, voyage-3.5-lite, voyage-code-3 (256/512/1024/2048 dimensions) and voyage-finance-2, voyage-law-2 (1024 only).
    • Package registration: workspace source, uv.lock, PACKAGE_STATUS.md (alpha, not in the meta-package), feature-usage index 90, the release smoke-import inventory, .env.example, a package README, AGENTS.md and a sample.
  • What is the impact of these changes? A new opt-in package. No existing package or public API changes, and nothing is added to agent-framework-core[all] or the core lazy-loading namespaces.
  • What do you want reviewers to focus on?
    • There is no default model. A missing model raises, and a name outside the supported table raises ValueError before any request. The table also keeps the SDK's locally executed open-weight models from being selected by accident.
    • dimensions is checked against the model and sent as output_dimension only when set. input_type ("document" or "query") and truncation are sent only when set.
    • Usage fails closed: a response without a token count raises IntegrationInvalidResponseException instead of reporting zero tokens.
    • Calls are split into consecutive requests that keep order and sum usage, by the 1000-input limit and by each model's per-request token ceiling (1M, 320K or 120K; Voyage AI documents none for voyage-code-4, which is split at 120K like the other 120K models). Tokens are counted with the SDK's count_tokens (its tokenizer is fetched from the Hugging Face Hub on first use); if counting fails, the call raises instead of sending an unsplit request.
    • Contextualized embeddings: input_type is required. Documents go out as a flat list of strings (one per document) with enable_auto_chunking=True and chunk_size=32_000, which is what the service accepts; a pre-chunked document raises ValueError. Queries go out unchunked. The client has no telemetry layer and is not a BaseEmbeddingClient.
    • Voyage AI error bodies ({"detail": ...}) map to the framework Integration* exceptions; 429 and 5xx map to IntegrationException.
    • Reranking and multimodal embeddings are not part of this change: the framework has no reranker or multimodal embedding abstraction.

Related Issue

Fixes #10360

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation, tests, documentation, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Adds agent-framework-voyageai, an alpha package with VoyageAIEmbeddingClient
and RawVoyageAIEmbeddingClient for Voyage AI text embedding models, built on
the official voyageai SDK.

The model is always named explicitly and must be one of voyage-4-large,
voyage-4, voyage-4-lite, voyage-code-4, voyage-3-large, voyage-3.5,
voyage-3.5-lite, voyage-code-3, voyage-finance-2 or voyage-law-2; there is no
default, and unknown names are rejected before any request so the SDK's local
open-weight models are never selected by accident. dimensions is validated
against the model's supported sizes and sent as output_dimension only when
set. VoyageAIEmbeddingOptions adds input_type ("document"/"query") and
truncation, both sent only when set.

Calls of more than 1000 inputs are split into consecutive requests that keep
vector order and sum usage. Usage fails closed: a response without a valid
token count raises instead of reporting zero. Voyage AI error bodies
({"detail": ...}) map to the framework integration exceptions.

Includes a package-local sample, unit tests for failure modes, and an
integration test that is skipped without VOYAGE_API_KEY. Feature-usage
index 90.
A response without usage or a token count fails inside the SDK while it builds
its result; report that as IntegrationInvalidResponseException instead of a
generic request failure. Also reject blank API keys and non-integer
dimensions, and keep non-text error details from escaping as TypeError.
@fzowl

fzowl commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Adds agent-framework-voyageai (alpha): VoyageAIEmbeddingClient for 10 Voyage AI text models on the official voyageai SDK, with an explicit model (no default), per-model dimensions, input_type, batching over 1000 inputs and fail-closed usage.

Checked: poe check -P voyageai (ruff, pyright, mypy, pyrefly, ty, zuban, 40 unit tests), scripts/tests, prek hooks. Live API calls for all 10 models (native dimension, 256 with query, 2048, batches), the negative cases (missing, unknown and other-provider model, unsupported dimension, bad input_type, bad key, over-length with truncation=False), and the sample. Not run: more than 1000 inputs live, the other Python versions, Windows/macOS.

Review: 2 rounds, final verdict APPROVE. Left open as follow-ups: service_url() ignores the SDK's Atlas (al-) endpoint and an injected client's base URL; the SDK's own token count is not range-checked.

Before opening upstream: CONTRIBUTING requires an agreed issue (ready-for-implementation), and the template's AI Assistance section is left for you to complete.

kwargs["output_dimension"] = dimensions

try:
response = await self.client.embed(list(values), model=model, **kwargs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Token aware batching!

Add Contextual models!

@fzowl fzowl Nov 14, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Both done.

Token-aware batching: calls are now split by each model's per-request token ceiling (1M for the -lite models, 320K for voyage-4 and voyage-3.5, 120K for the others, voyage-code-4 included) as well as by the 1000-input limit. Tokens are counted with the SDK's count_tokens; there is no estimation. If counting fails, the call raises instead of sending an unsplit request. Checked live on voyage-4-large: four ~31K-token inputs (124K tokens) went out as two requests (3 + 1) and usage was summed.

Contextualized models: VoyageAIContextualizedEmbeddingClient for voyage-context-4 and voyage-context-3. Documents go out as a flat list[str] with enable_auto_chunking=True and chunk_size=32_000, queries unchunked, and the chunk text is returned as chunks.


Examples:
.. code-block:: python

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ezt a példa kódot kipróbáltad?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yes. I ran this docstring example as written (voyage-4, input_type="document", dimensions=512) against the live API: one 512-dimension vector, usage {'input_token_count': 3, 'total_token_count': 3}. The README quick start also ran: two 1024-dimension vectors, usage 6 tokens. The docstring's top-level await follows the Mistral client's example, so it needs an async context to run.

… Voyage AI package

VoyageAIContextualizedEmbeddingClient embeds documents and queries with
voyage-context-4 and voyage-context-3. Contextualized embeddings return a
vector per chunk, which does not fit BaseEmbeddingClient, so the client has its
own method and result type, with the chunk text returned alongside the vectors.
Documents are sent as one string each with auto-chunking enabled and a chunk
size of 32,000 tokens; queries are sent unchunked. input_type is required and
the model is always named explicitly.

Both clients now split a call by the model's documented per-request token
ceiling as well as the 1000-input limit, counting tokens with the SDK
tokenizer only when the inputs could reach the ceiling.
…AI package

NFC normalization can grow UTF-8 text up to three times before tokenizing, so
the check that skips the tokenizer assumed too few tokens. Also report an SDK
error without a status as an invalid response, and reject a bare string passed
as the documents of a contextualized embeddings call.
@fzowl

fzowl commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Updated for the review comments: contextualized embeddings (voyage-context-4, voyage-context-3) and token-aware batching are in (49a3272, 3314a43). The description is updated to match.

Checked: poe check -P voyageai (ruff, pyright, mypy, pyrefly, ty, zuban, 81 unit tests), scripts/tests, prek hooks. Live API calls: both context models (document with chunk text, query, 256 and 2048 dimensions, a 2-chunk 45K-token document), the negative cases (no input_type, pre-chunked document, other provider's model, unsupported dimension), the real tokenizer path, and both samples. Not run: a call that actually spans several token-limited requests live (covered by unit tests with a mocked tokenizer), other Python versions, Windows/macOS.

Review: 2 more rounds on the new code, final verdict APPROVE. Left as follow-ups: service_url() ignores the SDK's Atlas (al-) endpoint and an injected client's base URL; no telemetry layer on the contextualized client.

… AI package

Calls to a model with a documented per-request token ceiling now always count
tokens with the voyageai SDK's count_tokens before splitting; the size-based
shortcut that skipped counting is removed.
…models

Voyage AI documents no per-request token ceiling for voyage-code-4. Every model
now has a ceiling, so token counting applies to all of them.
@fzowl

fzowl commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Follow-up on the token limits: voyage-code-4 is now split at 120K tokens like the other 120K models (Voyage AI documents no ceiling for it; a live 124K-token request was accepted), and every call to a model with a ceiling counts tokens with the SDK's count_tokens. The size-based shortcut is gone. Commits 141a5b9 and the one after it.

Checked live (real client and SDK): all 10 text models (native dimension, query at 256, 2048 batch, 1024 for finance/law), both context models (document with chunk text, query, 512 and 2048), a 2-chunk 45K-token document, and a 124K-token call that split into two requests. Not run: other Python versions, Windows/macOS.

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.

Python: [Feature]: Python: Add a Voyage AI embedding client package

2 participants