import { Query } from 'firebase-admin/firestore'; import { FirestoreDocument } from '../core/DocumentId.js'; import type { KeysOf } from '../utils/pathTypes.js'; /** * Supported Firestore vector distance measures for KNN similarity search. */ export declare const VectorDistanceMeasure: { readonly EUCLIDEAN: "EUCLIDEAN"; readonly COSINE: "COSINE"; readonly DOT_PRODUCT: "DOT_PRODUCT"; }; export type VectorDistanceMeasureValue = (typeof VectorDistanceMeasure)[keyof typeof VectorDistanceMeasure]; /** Maximum embedding dimension Firestore supports per vector index. */ export declare const VECTOR_MAX_DIMENSIONS = 2048; /** Maximum number of documents a single nearest-neighbor query may return. */ export declare const VECTOR_MAX_LIMIT = 1000; /** * Options for a Firestore KNN vector similarity search. */ export type FindNearestOptions, string> = Extract, string>> = Readonly<{ /** * Top-level document field containing the stored vector embedding. Firestore vector indexes are * defined on top-level fields, so this is constrained to `T`'s own string keys; use a cast for a * nested or unschematized field. */ vectorField: K; /** Query embedding used to rank nearest neighbors. */ queryVector: ReadonlyArray; /** Maximum documents to return (1–1000). */ limit: number; /** Distance measure used by Firestore for ranking. */ distanceMeasure: VectorDistanceMeasureValue; /** * Optional result field name where Firestore writes the computed distance per document. * Requires `@google-cloud/firestore` >= 7.10.0 (bundled with firebase-admin >= 13). * * Prefer a string **literal** for precise result typing (see {@link DistanceFieldResult}): a * literal is added as a numeric property and replaces any colliding model field. `'id'` is * rejected (the repository overlays the document id, which would overwrite the distance). A * non-literal `string` yields a conservative result type rather than typing every field as number. */ distanceResultField?: string; /** * Optional similarity threshold filter. * Requires `@google-cloud/firestore` >= 7.10.0 (bundled with firebase-admin >= 13). */ distanceThreshold?: number; }>; /** * Result shape when a computed distance field named `DF` is added to a base result `R`. * * - **Literal `DF`** (e.g. `'score'`): the distance **replaces** any colliding key * (`Omit & Record`) — matching Firestore's runtime overwrite — rather than * intersecting (which would collapse a collision to `never`). * - **Literal `'id'`** (reserved; rejected at runtime): resolves to `never` so the type cannot * describe a result the runtime validator forbids. * - **Broad `string`** (a non-literal field name, e.g. from a variable): conservative — `id` keeps * its ID type (a successful call can never use the rejected `'id'`), every other known field is * `R[K] | number` (the runtime name may collide with any one), and arbitrary keys are `unknown`. * It never promises that all known fields became numbers. Pass a string **literal** for precise * per-field typing. */ export type DistanceFieldResult = string extends DF ? { [K in keyof R]: K extends 'id' ? R[K] : R[K] | number; } & Record : 'id' extends DF ? never : Omit & Record; /** * Document shape returned from vector search, optionally including a computed distance field. See * {@link DistanceFieldResult} for the collision/reserved-`id`/broad-`string` rules. */ export type VectorSearchResult = DistanceField extends string ? DistanceFieldResult, DistanceField> : FirestoreDocument; /** * Detects a Firestore vector write value produced by `FieldValue.vector()`. */ export declare function isVectorFieldValue(value: unknown): boolean; /** * Validates nearest-neighbor options before delegating to the Firestore SDK. * * @throws {@link TypeError} when a numeric option is the wrong type, non-finite, outside its * supported range, or otherwise cannot be represented faithfully by the installed SDK */ export declare function validateFindNearestOptions(options: FindNearestOptions>): void; /** * Ensures the connected Firestore SDK supports the **object-form** `findNearest({ ... })` this * library issues (see {@link VectorQueryBuilder}), which requires `@google-cloud/firestore >= 7.10` * (guaranteed by `firebase-admin >= 13`; on `firebase-admin 12` only when the resolved * `@google-cloud/firestore` is `>= 7.10`). * * Detection is **capability-based**, not error-based. It (1) rejects a totally absent `findNearest` * (`<= 7.5`), then (2) probes the object form by constructing a throwaway `findNearest` with valid * minimal arguments. The positional-only `7.6`–`7.9` signature rejects a single object argument, so * the probe throws there and a deterministic compatibility error is surfaced; `7.10+` constructs the * probe and returns. Because this runs BEFORE the real `findNearest` call, a genuine construction * error from the real call (e.g. an invalid vector field path on a supported SDK) is **not** relabeled * as a version incompatibility — it propagates as an ordinary SDK error (review R1). The probe builds * a throwaway query object only (no I/O); the builder's guards ensure the query reaching this point * is findNearest-compatible, so on a supported SDK the valid-args probe constructs. */ export declare function assertVectorSearchSupported(query: Query): void;