UNPKG

voyage-ai-provider

Version:

Voyage AI Provider for running Voyage AI models with Vercel AI SDK

90 lines (86 loc) 4.2 kB
import { ProviderV1, EmbeddingModelV1 } from '@ai-sdk/provider'; import { FetchFunction } from '@ai-sdk/provider-utils'; type VoyageEmbeddingModelId = 'voyage-3-large' | 'voyage-3' | 'voyage-3-lite' | 'voyage-code-3' | 'voyage-finance-2' | 'voyage-multilingual-2' | 'voyage-law-2' | 'voyage-code-2' | 'voyage-large-2-instruct' | 'voyage-large-2' | 'voyage-2' | 'voyage-02' | 'voyage-01' | 'voyage-lite-01' | (string & NonNullable<unknown>); interface VoyageEmbeddingSettings { /** * The input type for the embeddings. Defaults to "query". * For query, the prompt is "Represent the query for retrieving supporting documents: ". * For document, the prompt is "Represent the document for retrieval: ". */ inputType?: 'query' | 'document'; /** * The number of dimensions for the resulting output embeddings. * * If not specified (defaults to null), the resulting output embeddings dimension is the default for the model. * `voyage-code-3` supports the following `outputDimension` values: 2048, 1024 (default), 512, and 256. * `voyage-3-large` supports the following `outputDimension` values: 2048, 1024 (default), 512, and 256. * * please refer to the model documentation for the supported values. * https://docs.voyageai.com/docs/embeddings */ outputDimension?: number; /** * The data type for the resulting output embeddings. * * Defaults to 'float'. * * Other options: 'int8', 'uint8', 'binary', 'ubinary'. * - 'float' is supported by all models. * - 'float': Each returned embedding is a list of 32-bit (4-byte) single-precision floating-point numbers. * - 'int8', 'uint8', 'binary', and 'ubinary' are supported by 'voyage-code-3'. * - 'int8' and 'uint8': Each returned embedding is a list of 8-bit (1-byte) integers ranging from -128 to 127 and 0 to 255, respectively. * - 'binary' and 'ubinary': Each returned embedding is a list of 8-bit integers that represent bit-packed, quantized single-bit embedding values: * 'int8' for 'binary' and 'uint8' for 'ubinary'. * The length of the returned list of integers is 1/8 of outputDimension (which is the actual dimension of the embedding). * The 'binary' type uses the offset binary method. * * https://docs.voyageai.com/docs/faq#what-is-quantization-and-output-data-types */ outputDtype?: 'float' | 'int8' | 'uint8' | 'binary' | 'ubinary'; /** * Whether to truncate the input texts to fit within the context length. */ truncation?: boolean; } interface VoyageProvider extends ProviderV1 { (modelId: VoyageEmbeddingModelId, settings?: VoyageEmbeddingSettings): EmbeddingModelV1<string>; /** @deprecated Use `textEmbeddingModel()` instead. */ embedding(modelId: VoyageEmbeddingModelId, settings?: VoyageEmbeddingSettings): EmbeddingModelV1<string>; /** @deprecated Use `textEmbeddingModel()` instead. */ textEmbedding(modelId: VoyageEmbeddingModelId, settings?: VoyageEmbeddingSettings): EmbeddingModelV1<string>; textEmbeddingModel: (modelId: VoyageEmbeddingModelId, settings?: VoyageEmbeddingSettings) => EmbeddingModelV1<string>; } interface VoyageProviderSettings { /** Use a different URL prefix for API calls, e.g. to use proxy servers. The default prefix is `https://api.voyageai.com/v1`. */ baseURL?: string; /** API key that is being send using the `Authorization` header. It defaults to the `VOYAGE_API_KEY` environment variable. */ apiKey?: string; /** Custom headers to include in the requests. */ headers?: Record<string, string>; /** Custom fetch implementation. You can use it as a middleware to intercept requests, or to provide a custom fetch implementation for e.g. testing. */ fetch?: FetchFunction; } /** Create a Voyage AI provider instance. */ declare function createVoyage(options?: VoyageProviderSettings): VoyageProvider; /** Default Voyage provider instance. */ declare const voyage: VoyageProvider; export { type VoyageProvider, type VoyageProviderSettings, createVoyage, voyage };