import type { RagChunk } from '../hallucination/rag.js'; import type { VectorSearchResult } from '../hallucination/retrieval.js'; import type { RetrieveOptions, SparseRetriever } from './retrievers.js'; /** Options for the Elasticsearch keyword index. */ export interface ElasticsearchKeywordIndexOptions { /** The cluster, such as `http://localhost:9200`, an Elastic Cloud endpoint, or an OpenSearch domain. */ url: string; /** The index chunks are kept in. */ index: string; /** Sent as `Authorization: ApiKey `. */ apiKey?: string; /** Sent as basic authentication, for a cluster with users instead of API keys. */ username?: string; /** The password for `username`. */ password?: string; /** The analyzer `migrate()` gives the `content` field, such as `english`. Defaults to the cluster's standard one. */ analyzer?: string; /** * When a write becomes searchable. `wait_for` (the default) returns once a search would see it, as * the vector stores do; `false` returns sooner and leaves it to the index's refresh interval. */ refresh?: 'wait_for' | boolean; /** Replaces the global `fetch`, for a proxy, retries, signed requests, or tests. */ fetch?: typeof globalThis.fetch; /** Headers added to every request. */ headers?: Record; /** Aborts a request that takes longer, in milliseconds. Defaults to 30 seconds. */ timeoutMs?: number; } /** Raised when the cluster answers with an error. */ export declare class ElasticsearchError extends Error { /** The HTTP status the cluster answered with. */ readonly status: number; /** The cluster's response body, as text. */ readonly body?: string | undefined; constructor(message: string, /** The HTTP status the cluster answered with. */ status: number, /** The cluster's response body, as text. */ body?: string | undefined); } /** * Keyword search in Elasticsearch or OpenSearch, through their REST API. * * No client library is a dependency: the index speaks HTTP through `fetch`, as the vector stores do, * so it runs wherever `fetch` does. Scores are the engine's own BM25, ranked in the cluster, so only * the best matches come back. A `SparseRetriever`, so `hybridRetriever()` fuses it with any vector * store. A metadata filter is an exact match on top-level fields, as in the vector stores. */ export declare class ElasticsearchKeywordIndex implements SparseRetriever { private readonly options; private readonly base; private readonly fetchImpl; constructor(options: ElasticsearchKeywordIndexOptions); /** * Creates the index unless it exists: `content` as analyzed text, `id` and `source` as keywords, * and every string under `metadata` as a keyword, so a filter matches it exactly. Never runs * implicitly. */ migrate(): Promise; /** Adds chunks, or replaces those whose id exists, in one bulk request. */ add(chunks: readonly RagChunk[]): Promise; /** Removes chunks by id. An id that is not held is ignored. */ delete(ids: readonly string[]): Promise; /** The chunks that best match a query's terms, best first, scored by the engine's BM25. */ retrieve(query: string, options?: RetrieveOptions): Promise; /** Chunks held. */ size(): Promise; private bulk; private request; }