Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/specs/feature-usage-bit-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ only to approved first-party endpoints.
| 87 | `hosting.telegram` | Telegram hosting converters | `agent_framework_hosting_telegram.telegram_to_run` |
| 88 | `lab` | Experimental Agent Framework Lab features | `agent_framework.lab` feature entry points |
| 89 | `nvidia` | NVIDIA NIM embedding client | `agent_framework_nvidia.NvidiaEmbeddingClient` |
| 90–127 | _reserved_ | future packages | — |
| 90 | `voyageai` | Voyage AI embedding client | `agent_framework_voyageai.VoyageAIEmbeddingClient` |
| 91–127 | _reserved_ | future packages | — |

## Index table — .NET (`agent-framework-dotnet`, version 1)

Expand Down
4 changes: 4 additions & 0 deletions python/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ MISTRAL_API_KEY=""
MISTRAL_CHAT_MODEL=""
MISTRAL_EMBEDDING_MODEL=""
MISTRAL_SERVER_URL=""
# Voyage AI
VOYAGE_API_KEY=""
VOYAGE_EMBEDDING_MODEL=""
VOYAGE_BASE_URL=""
# Observability (instrumentation is enabled by default; set "ENABLE_INSTRUMENTATION" to "false" to opt out)
ENABLE_SENSITIVE_DATA=true
OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317/"
2 changes: 1 addition & 1 deletion python/.github/skills/agent-framework-py-release/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ Contract:
`agent_framework_hosting`, `agent_framework_hosting_a2a`, `agent_framework_hosting_mcp`,
`agent_framework_hosting_responses`, `agent_framework_hosting_telegram`, `agent_framework_mongodb`,
`agent_framework_nvidia`, `agent_framework_oracle`, `agent_framework_postgres`, `agent_framework_qdrant`,
`agent_framework_sql_server`, and `agent_framework_typesafe`. See their package READMEs and exported `__all__`;
`agent_framework_sql_server`, `agent_framework_typesafe`, and `agent_framework_voyageai`. See their package READMEs and exported `__all__`;
the inventory test checks each selected public export. A new exception must also be reviewed in the consumer
allowlist before release.

Expand Down
1 change: 1 addition & 0 deletions python/PACKAGE_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ column records whether `pip install agent-framework` installs the workspace pack
| `agent-framework-sql-server` | `python/packages/sql-server` | `alpha` | `no` |
| `agent-framework-tools` | `python/packages/tools` | `beta` | `yes` |
| `agent-framework-typesafe` | `python/packages/typesafe` | `alpha` | `no` |
| `agent-framework-voyageai` | `python/packages/voyageai` | `alpha` | `no` |

## Deprecated / removed packages

Expand Down
62 changes: 62 additions & 0 deletions python/packages/voyageai/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Voyage AI Package (agent-framework-voyageai)

Integration with Voyage AI for text embedding generation and contextualized chunk embeddings.

## Implementation Notes

- Uses the official `voyageai` SDK (`voyageai.AsyncClient.embed`) for embedding requests. Framework
option, usage, and exception translation stays in this package.
- There is no default model. `model` (or `VOYAGE_EMBEDDING_MODEL`, or `options["model"]`) must name a
model in `_MODELS`; an unknown name raises `ValueError` before any request. The table also
keeps the SDK's local open-weight models from being selected, since those would run in-process.
- `dimensions` is validated against the model's supported sizes and sent as `output_dimension` only when
set. `input_type` (`"document"`/`"query"`) and `truncation` are sent only when set.
- A request holds at most 1000 inputs (`MAX_BATCH_SIZE`) and, per model, at most the tokens in
`_ModelSpec.max_request_tokens`. Voyage AI documents none for `voyage-code-4`; it uses 120K like the other
120K models (a live request of 124K tokens was accepted, so this is conservative).
`split_into_requests` splits larger calls into consecutive requests and `get_embeddings` sums usage. Tokens
are counted with the SDK's `client.count_tokens` (its tokenizer is fetched from the Hugging Face Hub on first
use); there is no estimation. A counting failure raises instead of sending an unsplit request.
- Contextualized embeddings do not fit `BaseEmbeddingClient` (several vectors per input), so
`VoyageAIContextualizedEmbeddingClient.get_contextualized_embeddings` has its own result type
(`VoyageAIContextualizedEmbeddings`, one `VoyageAIContextualizedEmbedding` per value with `embeddings` and
`chunks`) and no telemetry layer. `input_type` is required. Documents (`"document"`) are always a flat
`list[str]` with `enable_auto_chunking=True` and `chunk_size=32_000`; the API rejects auto-chunking with any
other input type or with pre-chunked inner lists. Queries are sent as `[[query], ...]` without chunking.
- Usage is read from the response's `usage.total_tokens`. A missing or invalid count raises
`IntegrationInvalidResponseException`; it is never reported as zero.
- Voyage AI error bodies are `{"detail": "<text>"}`. `_shared.error_detail` reads that field and
`_shared.raise_sdk_error` maps `401`/`403` to `IntegrationInvalidAuthException`, other `4xx` except `429` to
`IntegrationInvalidRequestException`, and everything else (including `429` and `5xx`) to
`IntegrationException`.
- The SDK retries `429`/`503`/timeouts only when `max_retries` is set. The client keeps the SDK default (no
retries); pass a pre-configured `voyageai.AsyncClient` to change that.

## Main Classes

- **`VoyageAIEmbeddingClient`** - Embedding client for Voyage AI text models, with telemetry
- **`RawVoyageAIEmbeddingClient`** - The same client without the telemetry layer
- **`VoyageAIEmbeddingOptions`** - Options TypedDict (`model`, `dimensions`, `input_type`, `truncation`)
- **`VoyageAIEmbeddingSettings`** - TypedDict settings for Voyage AI configuration
- **`VoyageAIContextualizedEmbeddingClient`** - Contextualized chunk embeddings for `voyage-context-4`/`-3`
- **`VoyageAIContextualizedEmbeddingOptions`** / **`VoyageAIContextualizedEmbeddingSettings`** - Its options and settings
- **`VoyageAIContextualizedEmbeddings`** / **`VoyageAIContextualizedEmbedding`** - Its result types

## Usage

```python
from agent_framework_voyageai import VoyageAIEmbeddingClient

# Requires VOYAGE_API_KEY environment variable (or pass api_key= directly)
client = VoyageAIEmbeddingClient(model="voyage-4")
result = await client.get_embeddings(["Hello, world!"], options={"input_type": "document"})
print(result[0].vector)
```

## Import Path

The package is alpha, so there is no `agent_framework.voyageai` namespace in core yet.

```python
from agent_framework_voyageai import VoyageAIEmbeddingClient
```
21 changes: 21 additions & 0 deletions python/packages/voyageai/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
125 changes: 125 additions & 0 deletions python/packages/voyageai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Get Started with Microsoft Agent Framework Voyage AI

An alpha [Voyage AI](https://www.voyageai.com/) text embedding integration for Microsoft Agent Framework. Please install this package:

```bash
pip install agent-framework-voyageai --pre
```

and see the [README](https://github.com/microsoft/agent-framework/tree/main/python/README.md) for more information.

See the [Voyage AI samples](samples/README.md) for a runnable example.

## Embedding Client

The `VoyageAIEmbeddingClient` generates text embeddings, and `VoyageAIContextualizedEmbeddingClient` generates
contextualized chunk embeddings, with the official
[`voyageai`](https://pypi.org/project/voyageai/) SDK.

### Quick Start

```python
from agent_framework_voyageai import VoyageAIEmbeddingClient

# Reads VOYAGE_API_KEY from the environment. The model is always named explicitly:
# pass it here, or set VOYAGE_EMBEDDING_MODEL.
client = VoyageAIEmbeddingClient(model="voyage-4")

result = await client.get_embeddings(
["Hello, world!", "How are you?"],
options={"input_type": "document"},
)
for embedding in result:
print(f"Dimensions: {embedding.dimensions}")
print(result.usage)
```

### Configuration

| Environment Variable | Description |
|---|---|
| `VOYAGE_API_KEY` | Your Voyage AI API key |
| `VOYAGE_EMBEDDING_MODEL` | Embedding model name (for example `voyage-4`). There is no default model |
| `VOYAGE_BASE_URL` | Optional endpoint override |

### Models

There is no default model. The client rejects a missing model, or a name outside this table, before
it sends a request.

| Model | `dimensions` |
|---|---|
| `voyage-4-large`, `voyage-4`, `voyage-4-lite`, `voyage-code-4` | 256, 512, 1024 (default), 2048 |
| `voyage-3-large`, `voyage-3.5`, `voyage-3.5-lite`, `voyage-code-3` | 256, 512, 1024 (default), 2048 |
| `voyage-finance-2`, `voyage-law-2` | 1024 |

### Options

`VoyageAIEmbeddingOptions` adds two Voyage AI fields to the common embedding options:

| Option | Values | Purpose |
|---|---|---|
| `input_type` | `"document"`, `"query"` | Voyage AI prepends a retrieval prompt for each. Omitted, nothing is prepended |
| `truncation` | `True`, `False` | Shorten over-length input, or reject it. Omitted, the service default (`True`) applies |

`dimensions` is sent as `output_dimension`, and only when set. For retrieval, embed stored documents with
`input_type="document"` and search text with `input_type="query"`. Vector collections forward
`embeddings_options` to each request:

```python
await collection.upsert(notes, embeddings_options={"input_type": "document"})
results = await collection.search("How do I call a model?", embeddings_options={"input_type": "query"})
```

### Requests and usage

A request holds at most 1000 inputs, and each model has a ceiling on the tokens of one request (1M for
`voyage-4-lite` and `voyage-3.5-lite`, 320K for `voyage-4` and `voyage-3.5`, 120K for the others). Voyage AI
documents no ceiling for `voyage-code-4`; it is split like the other 120K models, which is conservative. The client
splits larger calls into consecutive requests within both limits, returns the vectors in order, and sums usage.

Tokens are counted with the SDK's `count_tokens`, which uses the model's own tokenizer. The tokenizer is
downloaded from the Hugging Face Hub on first use. If tokens cannot be counted, the call raises
`IntegrationException` instead of sending an unsplit request.

Usage comes from the token count the service reports. A response without one raises
`IntegrationInvalidResponseException` instead of reporting zero tokens.

Only the models in the table above are accepted. The `voyageai` SDK can also run some open-weight models
on the local machine, and the client does not select them.

## Contextualized Embedding Client

Contextualized embeddings give each chunk of a document a vector that also reflects the rest of the document.
One document yields several vectors, which does not fit `get_embeddings` (one vector per input), so
`VoyageAIContextualizedEmbeddingClient` has its own method and result type. It has no telemetry layer.

```python
from agent_framework_voyageai import VoyageAIContextualizedEmbeddingClient

# The model is always named explicitly: pass it here, or set VOYAGE_CONTEXTUALIZED_EMBEDDING_MODEL.
client = VoyageAIContextualizedEmbeddingClient(model="voyage-context-4")

documents = await client.get_contextualized_embeddings(
["A long document ...", "Another long document ..."],
options={"input_type": "document", "dimensions": 512},
)
for document in documents:
for chunk, embedding in zip(document.chunks or [], document.embeddings):
print(chunk[:40], embedding.dimensions)

queries = await client.get_contextualized_embeddings(["Why do cats purr?"], options={"input_type": "query"})
```

| Model | `dimensions` |
|---|---|
| `voyage-context-4`, `voyage-context-3` | 256, 512, 1024 (default), 2048 |

- `input_type` is required. `"document"` sends each value as one whole document (a flat list of strings, one
string per document) with `enable_auto_chunking=True` and `chunk_size=32_000`, so Voyage AI does the
chunking. A pre-chunked document, such as a list of strings as one value, raises `ValueError`: the service
rejects it when it chunks itself. `"query"` sends each value as one query and does not chunk.
- Each result holds one vector per chunk in `embeddings`, and the text of each chunk in `chunks` when the service
returned it. Queries have one vector and `chunks` is `None`.
- Requests are split by the 1000-input and 120K-token limits like the text client, and the same fail-closed
usage and error mapping apply.
35 changes: 35 additions & 0 deletions python/packages/voyageai/agent_framework_voyageai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) Microsoft. All rights reserved.

import importlib.metadata

from ._contextualized_embedding_client import (
VoyageAIContextualizedEmbedding,
VoyageAIContextualizedEmbeddingClient,
VoyageAIContextualizedEmbeddingOptions,
VoyageAIContextualizedEmbeddings,
VoyageAIContextualizedEmbeddingSettings,
)
from ._embedding_client import (
RawVoyageAIEmbeddingClient,
VoyageAIEmbeddingClient,
VoyageAIEmbeddingOptions,
VoyageAIEmbeddingSettings,
)

try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0" # Fallback for development mode

__all__ = [
"RawVoyageAIEmbeddingClient",
"VoyageAIContextualizedEmbedding",
"VoyageAIContextualizedEmbeddingClient",
"VoyageAIContextualizedEmbeddingOptions",
"VoyageAIContextualizedEmbeddingSettings",
"VoyageAIContextualizedEmbeddings",
"VoyageAIEmbeddingClient",
"VoyageAIEmbeddingOptions",
"VoyageAIEmbeddingSettings",
"__version__",
]
Loading