/** * Extended VoyageAI client with local model support, client-side chunking and client metadata headers */ import type * as VoyageAI from "../api/index.js"; import { VoyageAIClient as GeneratedClient } from "../Client.js"; import { HttpResponsePromise } from "../core/fetcher/HttpResponsePromise.js"; import type { TokenizeResult } from "../local/tokenizer.js"; import { type ClientMetadataEntry } from "./client-metadata.js"; export type ChunkFn = (text: string) => string[]; export interface ContextualizedEmbedOptions extends VoyageAI.ContextualizedEmbedRequest { chunkFn?: ChunkFn; } export interface ContextualizedEmbeddingsResultItem { index: number; embeddings: number[][]; chunkTexts?: string[]; } export interface ContextualizedEmbedResult { results: ContextualizedEmbeddingsResultItem[]; totalTokens: number; chunkTexts?: string[][]; chunkerVersion?: string; rawResponse: VoyageAI.ContextualizedEmbedResponse; } export declare class VoyageAIClient extends GeneratedClient { private readonly _wrappers; constructor(options?: GeneratedClient.Options); /** * Voyage embedding endpoint receives as input a string (or a list of strings) and other arguments such as the preferred model name, and returns a response containing a list of embeddings. * * For local models (e.g., 'voyage-4-nano'), embeddings are computed locally using Transformers.js. * For all other models, the request is forwarded to the Voyage AI API. * * @param {VoyageAI.EmbedRequest} request * @param {GeneratedClient.RequestOptions} requestOptions - Request-specific configuration. * * @example * // Local embedding (no API key required) * await client.embed({ * input: "hello world", * model: "voyage-4-nano" * }) * * @example * // API embedding * await client.embed({ * input: "hello world", * model: "voyage-3-large" * }) */ embed(request: VoyageAI.EmbedRequest, requestOptions?: GeneratedClient.RequestOptions): HttpResponsePromise; /** * Contextualized embeddings with client-side chunking and server-side auto-chunking support. * * Returns a `ContextualizedEmbedResult` wrapping the API response with extracted * embeddings, chunk texts, and token counts — mirroring the Python SDK's * `ContextualizedEmbeddingsObject`. * * @param request - Embed request with optional `chunkFn` for client-side chunking. * @param requestOptions - Request-specific configuration. */ contextualizedEmbed(request: ContextualizedEmbedOptions, requestOptions?: GeneratedClient.RequestOptions): Promise; /** * Tokenize texts using the specified model's tokenizer. * Works with both local models (e.g., 'voyage-4-nano') and API models (e.g., 'voyage-3-large'). * * @param texts - Array of strings to tokenize * @param model - Voyage model name * @returns Array of TokenizeResult, each containing tokens (string[]) and ids (number[]) * * @example * const results = await client.tokenize(["hello world"], "voyage-4-nano"); * console.log(results[0].tokens); // ["hello", "world"] * console.log(results[0].ids); // [123, 456] */ tokenize(texts: string[], model: string): Promise; /** * Register a wrapper library's metadata so it is included in subsequent * requests via the `X-VoyageAI-Wrapper` header. Name and version are trimmed; * duplicate entries (same trimmed name + version) are silently ignored. * * @param entry - The wrapper name and version to register. * @throws Error if the name or version is not a string, is empty after trimming, * contains anything but printable ASCII, or contains the reserved `|` / `/` delimiters. * * @example * client.appendClientMetadata({ name: "mem0", version: "1.2.3" }); */ appendClientMetadata(rawEntry: ClientMetadataEntry): void; } export declare function buildContextualizedResult(response: VoyageAI.ContextualizedEmbedResponse, clientChunkTexts?: string[][]): ContextualizedEmbedResult; export declare function validateAndNormalizeContextualizedInputs(request: VoyageAI.ContextualizedEmbedRequest, chunkFn?: ChunkFn): VoyageAI.ContextualizedEmbedRequest; export declare function applyChunking(inputs: string[][], chunkFn: ChunkFn): string[][]; export declare function defaultChunkFn(chunkSize?: number, chunkOverlap?: number): ChunkFn;