Repository navigation
Conversation
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.
|
Adds Checked: Review: 2 rounds, final verdict APPROVE. Left open as follow-ups: Before opening upstream: CONTRIBUTING requires an agreed issue ( |
| kwargs["output_dimension"] = dimensions | ||
|
|
||
| try: | ||
| response = await self.client.embed(list(values), model=model, **kwargs) |
There was a problem hiding this comment.
Token aware batching!
Add Contextual models!
There was a problem hiding this comment.
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 | ||
|
|
There was a problem hiding this comment.
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.
|
Updated for the review comments: contextualized embeddings ( Checked: Review: 2 more rounds on the new code, final verdict APPROVE. Left as follow-ups: |
… 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.
|
Follow-up on the token limits: Checked live (real client and SDK): all 10 text models (native dimension, |
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
InMemoryCollectionand the other vector stores currently have to write their ownBaseEmbeddingClient.Description & Review Guide
Adds an alpha package,
agent-framework-voyageai, modelled onagent-framework-mistralandagent-framework-nvidia. It uses the officialvoyageaiSDK, as the Mistral package usesmistralai.VoyageAIEmbeddingClientandRawVoyageAIEmbeddingClient(with and without the telemetry layer),VoyageAIEmbeddingOptionsandVoyageAIEmbeddingSettings(VOYAGE_API_KEY,VOYAGE_EMBEDDING_MODEL,VOYAGE_BASE_URL).VoyageAIContextualizedEmbeddingClientforvoyage-context-4andvoyage-context-3, with its ownget_contextualized_embeddingsmethod and result type (a vector per chunk, plus the chunk text), because one document yields several vectors andget_embeddingsreturns one vector per input.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) andvoyage-finance-2,voyage-law-2(1024 only).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.mdand a sample.agent-framework-core[all]or the core lazy-loading namespaces.ValueErrorbefore any request. The table also keeps the SDK's locally executed open-weight models from being selected by accident.dimensionsis checked against the model and sent asoutput_dimensiononly when set.input_type("document"or"query") andtruncationare sent only when set.IntegrationInvalidResponseExceptioninstead of reporting zero tokens.voyage-code-4, which is split at 120K like the other 120K models). Tokens are counted with the SDK'scount_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.input_typeis required. Documents go out as a flat list of strings (one per document) withenable_auto_chunking=Trueandchunk_size=32_000, which is what the service accepts; a pre-chunked document raisesValueError. Queries go out unchunked. The client has no telemetry layer and is not aBaseEmbeddingClient.{"detail": ...}) map to the frameworkIntegration*exceptions;429and5xxmap toIntegrationException.Related Issue
Fixes #10360
AI Assistance
AI assistance details: implementation, tests, documentation, and this PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.