import type { DefaultApi } from "./apis/DefaultApi"; import type { MetadataFieldPolicy, MetadataResult, VectorItem } from "./models"; import type { DeleteResponse, FilterExpression, GetResultItem, QueryResponse, TrainResponse, UpsertResponse } from "./types"; export declare class EncryptedIndex { private indexName; private readonly indexKeyHex?; private api; private dimensionCached?; private metricCached?; private withKey; constructor(indexName: string, indexKey: Uint8Array | undefined, api: DefaultApi); private describeIndex; getIndexName(): Promise; isTrained(): Promise; isTraining(): Promise; private refreshDimensionAndMetric; /** * Vector dimension. `0` until the first upsert when the index was created * without an explicit `dimension`; cached once it is known. */ getDimension(): Promise; getMetric(): Promise; getNLists(): Promise; /** * Delete an index * @returns Promise with the result of the operation */ deleteIndex(): Promise; /** * Retrieve vectors by their IDs * @param ids IDs of vectors to retrieve * @param include Fields to include in results * @returns Promise with the retrieved vectors */ get({ ids, include, }: { ids: string[]; include?: string[]; }): Promise; /** * Train the index for efficient querying * @param batchSize Size of batches for training * @param maxIters Maximum number of iterations * @param tolerance Convergence tolerance * @param nLists Number of Voronoi cells/clusters for IVF indexes * @returns Promise with the result of the operation */ train({ nLists, batchSize, maxIters, tolerance, maxMemory, }?: { nLists?: number; batchSize?: number; maxIters?: number; tolerance?: number; maxMemory?: number; }): Promise; /** * Add or update vectors in the index * * This method accepts either items (VectorItem[]) or parallel arrays (ids + vectors) * * @param items Array of VectorItems containing id, vector, and optional metadata/contents * @param ids Array of ID strings for each vector (used with vectors parameter) * @param vectors Array of vector embeddings corresponding to each ID (used with ids parameter) * @returns Promise resolving to operation result with status and details * @throws Error with detailed validation information for invalid inputs */ upsert({ items, ids, vectors, metadata, contents, }: { items?: VectorItem[]; ids?: string[]; vectors?: number[][] | Float32Array; metadata?: (Record | null)[]; contents?: (string | null)[]; }): Promise; /** * Search for semantically similar vectors in the index. * Supports single vector, batch vectors, or content-based queries. * * @param queryVectors Single vector [0.1, 0.2] or batch [[0.1, 0.2], [0.3, 0.4]] * @param queryContents Optional text content to embed and search (alternative to queryVectors) * @param topK Maximum number of results to return per query * @param nProbes Number of cluster centers to search * @param filters Metadata filters (MongoDB-style queries supported) * @param include Fields to include in results * @param greedy Use faster approximate search * @param text Query text for a BM25 leg — turns this into a hybrid (BM25 + * vector) query against an index with at least one `full_text` field; a * query vector is still required. Hybrid results carry a fused `score` * (larger = more relevant) instead of `distance`. Omitted/empty leaves the * query text-free (pure vector search). * @param textFields `full_text` fields the text leg searches; omitted means * all of them. Naming a non-full-text field raises. * @param textFieldWeights Per-field weights on the summed per-field BM25 * scores, parallel to the searched fields. Omitted means 1.0 each. * @param requireAllTerms Require every query term to match (AND) instead of * any (OR, the default). * @param alpha Leg blend in `[0, 1]`: 0 = pure BM25, 1 = pure vector; omitted * means 0.5. * @param rrfK RRF rank-smoothing constant (> 0; omitted means 60). * @param windowMult Per-leg candidate depth as a multiple of `topK` (>= 1; * omitted means 3). * @returns Promise resolving to QueryResponse * @throws Error if neither queryVectors nor queryContents provided */ query({ queryVectors, queryContents, topK, nProbes, filters, include, greedy, rerankMult, dimension, text, textFields, textFieldWeights, requireAllTerms, alpha, rrfK, windowMult, }: { queryVectors?: number[] | number[][] | Float32Array; queryContents?: string; topK?: number; nProbes?: number; filters?: FilterExpression; include?: string[]; greedy?: boolean; rerankMult?: number; dimension?: number; text?: string; textFields?: string[]; textFieldWeights?: number[]; requireAllTerms?: boolean; alpha?: number; rrfK?: number; windowMult?: number; }): Promise; /** * Delete vectors from the index * @param ids IDs of vectors to delete * @returns Promise with the result of the operation */ delete({ ids }: { ids: string[]; }): Promise; /** * Find items by metadata alone — no query vector, no distances. * * The filter is resolved entirely from the encrypted metadata index, so this * works on untrained indexes and never decrypts vectors. It is also the one * read path where the index's `metadataSchema` is enforced rather than just * steering performance: `$regex`/`$contains` need a `pattern` field, and a * field created with `filterable: false` cannot be filtered on at all. Both * reject — run the same filter through `query()` with a vector if you need * them, which post-filters on the decrypted metadata instead. * * Returns `MetadataResult` rows (`{ id }`, matching core's * `list[MetadataResult]`). Passing `text` adds a BM25 full-text leg (requires * an index with at least one `full_text` field): results are then ranked by * relevance and each row also carries a `score` (`{ id, score }`, descending * score); `filters` given alongside acts as a pre-filter and `orderBy` is not * supported with `text`. * * @param filters Metadata filters; omitted or empty matches everything * @param topK Cap on results returned, applied AFTER `orderBy`; omit for all * @param orderBy Metadata field to sort matches by, post-filter — either a * field name or a MongoDB-style single-field object (`{ views: -1 }`, * which sets the direction too). Not supported with `text`. * @param ascending Sort direction when `orderBy` is a plain field name * (default true) * @param text Query text for the BM25 leg. Omitted/empty keeps this a * filter-only query returning `{ id }` rows (no score). * @param textFields `full_text` fields the text leg searches; omitted means * all of them. Naming a non-full-text field raises. * @param textFieldWeights Per-field weights on the summed per-field BM25 * scores, parallel to the searched fields. Omitted means 1.0 each. * @param requireAllTerms Require every query term to match (AND) instead of * any (OR, the default). * @returns Promise with a list of `{ id }` rows (`MetadataResult[]`). Without * `text`: ordered when `orderBy` was given, no `score` key. With `text`: * each row also carries `score`, ranked by descending BM25 score. */ queryMetadata({ filters, topK, orderBy, ascending, text, textFields, textFieldWeights, requireAllTerms, }?: { filters?: FilterExpression; topK?: number; orderBy?: string | { [field: string]: number; }; ascending?: boolean; text?: string; textFields?: string[]; textFieldWeights?: number[]; requireAllTerms?: boolean; }): Promise; /** * The per-field metadata indexing policy recorded at create time, as * `{ field: { filterable, pattern, fullText } }`. * * Empty object when the index uses the default index-everything posture, or * when the service predates the feature — callers never have to distinguish * those from a missing field. `fullText` marks a field routed through the * BM25 analyzer (searchable by `query`/`queryMetadata` with `text`); see * {@link bm25} for the scorer config. * * @returns Promise with the policy keyed by field name */ metadataSchema(): Promise<{ [field: string]: Required; }>; /** * BM25 scorer config the index reports back, as * `{ k1, b, analyzerVersion }`, or `null` when the index has no `fullText` * field (BM25 is opt-in and derived, never flagged). * * `k1`/`b` are the tuning parameters supplied at create time or their * defaults; `analyzerVersion` identifies the tokenizer/stemmer pipeline the * corpus was indexed with. * * @returns Promise with the BM25 config, or `null` when not configured */ bm25(): Promise<{ k1: number; b: number; analyzerVersion?: string | null; } | null>; /** * List all vector IDs in the index * @returns Promise with object containing array of vector IDs and count */ listIds(): Promise<{ ids: string[]; count: number; }>; /** * Internal method: Add or update vectors using binary format for efficiency. * Called automatically by upsert() when Float32Array is passed. */ private _upsertBinary; /** * Internal method: Query vectors using binary format for efficiency. * Called automatically by query() when Float32Array is passed. */ private _queryBinary; /** * Mint a user API key scoped to this index. * * @param permissions Non-empty subset of `{"read", "write"}`. The grant * is enforced cryptographically by the service, not by a checked * policy field. * @returns `{ userId, apiKey }`. The `apiKey` is returned **exactly * once** and is never stored by the service — capture it now, it * cannot be recovered. Hand it to the user; they authenticate by * passing it as `apiKey` to `CyborgDB` and need no index key of * their own. * @throws Error if the user could not be created (e.g. the client is * not using the root key, or `permissions` is invalid). */ createUser({ permissions, }: { permissions: string[]; }): Promise<{ userId: string; apiKey: string; }>; /** * List the users provisioned for this index. * * @returns Array of `{ userId, permissions }`. Permissions are derived * from which wrapped keys exist for each user (the cryptographic * source of truth), not a stored field. * @throws Error if the users could not be listed (e.g. the client is * not using the root key). */ listUsers(): Promise<{ userId: string; permissions: string[]; }[]>; /** * Revoke a user, erasing their wrapped keys for this index. * * After this returns, the user's API key is rejected on the next * request — the service can no longer unwrap any key for them. * * @param userId The hex `userId` returned by `createUser` (also * surfaced by `listUsers`). * @throws Error if the user could not be deleted. */ deleteUser({ userId }: { userId: string; }): Promise; }