/** * EmbeddingProvider implementation backed by Google's Gemini embeddings API. * * Uses native `fetch` so it works in Cloudflare Workers + Node + browsers * without an SDK dependency. Templates pass in the API key (and optionally * a custom `baseUrl` for proxies). * * Models supported by default: * - `gemini-embedding-001` — 3072d, multilingual, current recommendation. * Supports Matryoshka representation learning (MRL) — request a smaller * output dimension via `outputDimensionality` to reduce storage cost. * - `text-embedding-004` — 768d, multilingual, legacy stable. * * See `docs/architecture/catalog-architecture.md` for the design. */ import { chunkForBatch, type EmbeddingProvider } from "./contract.js"; /** * Known Gemini embedding models. `dimensions` is the *native* size; when * `outputDimensionality` is set in the provider options, the effective * vector size is whatever the caller requested (Gemini truncates server-side * via MRL on `gemini-embedding-001`). */ declare const GEMINI_MODELS: { readonly "gemini-embedding-001": { readonly dimensions: 3072; readonly maxTokensPerInput: 2048; readonly maxBatchSize: 100; readonly multilingual: true; readonly supportsOutputDimensionality: true; }; readonly "text-embedding-004": { readonly dimensions: 768; readonly maxTokensPerInput: 2048; readonly maxBatchSize: 100; readonly multilingual: true; readonly supportsOutputDimensionality: false; }; }; export type GeminiEmbeddingModel = keyof typeof GEMINI_MODELS; /** * Tasks Gemini optimizes embeddings for. `RETRIEVAL_DOCUMENT` is the right * default for indexed catalog docs; switch to `RETRIEVAL_QUERY` when * embedding a search query at read time. The provider keeps a single task * type per instance — wire two providers if you index and query separately. */ export type GeminiTaskType = "RETRIEVAL_DOCUMENT" | "RETRIEVAL_QUERY" | "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY"; export interface GeminiEmbeddingProviderOptions { /** * API key to authenticate with. In `auth: "google"` mode, this is the * Google AI Studio key. In `auth: "bearer"` mode (e.g. when routing * through the Voyant Cloud AI gateway), this is the gateway's bearer * token. */ apiKey: string; /** * How to attach the API key to outbound requests. * - `"google"` (default) — `x-goog-api-key: `. Use when * talking directly to `generativelanguage.googleapis.com`. * - `"bearer"` — `Authorization: Bearer `. Use when routing * through the Voyant Cloud `/ai/v1/gemini` gateway, which forwards * to Google with the org's saved provider key. */ auth?: "google" | "bearer"; /** * Embedding model to use. Default: `gemini-embedding-001`. * Switching models is a deliberate `bulkReindex` operation — the catalog * plane scopes vector queries to documents matching the active * `embedding_model_id`, so mid-migration mixes are handled cleanly. */ model?: GeminiEmbeddingModel; /** * Output vector size for MRL-capable models. When omitted, the model's * native dimension is used. Only `gemini-embedding-001` supports this. * Smaller dims reduce storage / query cost at some quality loss. */ outputDimensionality?: number; /** * Task type the embedded text will be used for. Default: * `RETRIEVAL_DOCUMENT` (right for ingestion). Use `RETRIEVAL_QUERY` for * read-side query embedding. */ taskType?: GeminiTaskType; /** * Override the API base URL — useful for a corporate proxy or a custom * Vertex-compatible deployment. Default: * `https://generativelanguage.googleapis.com/v1beta`. */ baseUrl?: string; /** * Optional `fetch` override for testing or custom transport. Default: * the global `fetch`. Must follow the standard Fetch API contract. */ fetchImpl?: typeof fetch; /** * Override the model id stamped onto search-index documents. Defaults * to `gemini//v1` — keep this stable across deployments so * documents stay queryable across instances. */ modelId?: string; } /** * Build a Gemini-backed EmbeddingProvider. */ export declare function createGeminiEmbeddingProvider(options: GeminiEmbeddingProviderOptions): EmbeddingProvider; /** * Re-export the chunking helper alongside the Gemini provider so callers * can `embedBatched(provider, texts)` for very large inputs. */ export { chunkForBatch, GEMINI_MODELS };