import { FirestoreQueryBuilder } from '../core/QueryBuilder.js'; import type { QueryFilterFactory, QueryExplainResult } from '../core/QueryBuilder.js'; import { FirestoreDocument } from '../core/DocumentId.js'; import { DeepPartial, FieldPaths, OmitId, KeysOf } from '../utils/pathTypes.js'; import { FieldPath, Filter, Query, WhereFilterOp } from 'firebase-admin/firestore'; import { DistanceFieldResult, FindNearestOptions } from './VectorSearch.js'; /** * Options for {@link VectorQueryBuilder.explain}, derived from Admin SDK `Query.explain` (same * D9 alias pattern as core — firebase-admin does not re-export `ExplainOptions` by name). */ type ExplainOptions = NonNullable[0]>; /** * Query builder extension that adds Firestore KNN vector similarity search. * Wraps the core {@link FirestoreQueryBuilder} and delegates standard filters * until `findNearest()` transitions the query into vector mode. */ export declare class VectorQueryBuilder> { private coreBuilder; private vectorQuery; private projectionActive; private selectedFields; constructor(coreBuilder: FirestoreQueryBuilder); /** * Throws when vector mode is active and a standard query mutator is invoked. */ private assertNotVectorMode; /** * Throws for operations Firestore does not support on vector queries. */ private rejectInVectorMode; /** * Add a where clause before executing a vector search pre-filter. */ where(field: FieldPaths> | FieldPath, op: WhereFilterOp, value: unknown): this; /** * Add a **composite** (nested `AND` / `OR`) pre-filter before executing a vector search — the * composite counterpart of {@link where}, delegating to * {@link FirestoreQueryBuilder.whereFilter} on the wrapped core builder. * * Firestore applies the pre-filter before the nearest-neighbor scan, so the same composite filter * semantics and server-side limits apply as for a normal query, and the filtered fields must be * part of the vector index configuration. * * ⚠️ Inherits the inequality caveat from {@link FirestoreQueryBuilder.whereFilter}: an inequality * inside an `or()` branch excludes documents missing that field, including documents matched by * another branch. Prefer equality / `in` / `array-contains` branches in a vector pre-filter. * * @example * const nearby = await docRepo.vectorQuery() * .whereFilter(f => f.or(f.where('category', '==', 'a'), f.where('category', '==', 'b'))) * .findNearest({ vectorField: 'embedding', queryVector: [1, 0, 0], limit: 5, * distanceMeasure: 'EUCLIDEAN' }) * .get(); */ whereFilter(build: (f: QueryFilterFactory>) => Filter): this; /** * Select specific fields before findNearest(). The projection narrows the result shape and * composes through findNearest() (fields projected away become compile errors when accessed). * * Do NOT list `distanceResultField` here — it is a computed output field appended by * findNearest(), not a stored document field, and it is added to the result type automatically * when you configure it on findNearest(). */ select(...fields: (FieldPaths> | FieldPath)[]): VectorQueryBuilder>>; /** * Configure a Firestore nearest-neighbor vector search. */ findNearest>, string>, DF extends string | undefined = undefined>(options: FindNearestOptions, K> & { distanceResultField?: DF; }): VectorQueryBuilder : R>; /** * Execute the vector query and return all matching documents. */ get(): Promise; /** * Plans / optionally executes this vector query (Admin SDK VectorQuery.explain). * * Requires {@link findNearest} first — explaining the prefilter query alone would silently omit * the nearest-neighbor stage. * * Same `{ metrics, documents }` contract as {@link FirestoreQueryBuilderBase.explain}, including * `documents: null` for plan-only and `documents: []` for an empty analyzed result. Emulator: * throws `No explain results` (no metrics from the emulator). * * Note: `explainStream` does not exist on VectorQuery in the Admin SDK; it is not offered here. * The typeof guard below is defense-in-depth: `findNearest` already requires firestore >= 7.10, * which includes VectorQuery.explain (since 7.8). */ explain(options?: ExplainOptions): Promise>; /** * Return the single nearest document or null when no matches exist. */ getOne(): Promise; /** * Guarded — orderBy is not supported on vector query builders. */ orderBy(): this; /** * Guarded — real-time listeners are not supported for vector queries. */ onSnapshot(): Promise; /** * Guarded — streaming is not supported for vector queries. */ stream(): never; } export {};