/**
 * Full-text search across BRAIN memory using SQLite FTS5.
 * Uses raw SQL via nativeDb because drizzle doesn't support FTS5 virtual tables.
 *
 * Falls back to LIKE queries if FTS5 is not available (some SQLite builds lack it).
 *
 * @task T5130
 * @epic T5149
 */
import type { DatabaseSync } from 'node:sqlite';
import type { BrainDecisionRow, BrainLearningRow, BrainObservationRow, BrainPatternRow } from '../store/brain-schema.js';
/** Search result with BM25 rank. */
export interface BrainSearchResult {
    decisions: BrainDecisionRow[];
    patterns: BrainPatternRow[];
    learnings: BrainLearningRow[];
    observations: BrainObservationRow[];
}
/** Search options. */
export interface BrainSearchOptions {
    /** Max results per table. Default 10. */
    limit?: number;
    /** Which tables to search. Default: all four. */
    tables?: Array<'decisions' | 'patterns' | 'learnings' | 'observations'>;
}
/**
 * Create FTS5 virtual tables and content-sync triggers if they don't exist.
 *
 * Uses content= to sync from main tables, so inserts to main tables
 * auto-populate FTS. UPDATE/DELETE require triggers.
 *
 * @task T5130
 */
export declare function ensureFts5Tables(nativeDb: DatabaseSync): boolean;
/**
 * Rebuild FTS5 indexes from the content tables.
 * Useful after bulk inserts that bypass triggers.
 *
 * @task T5130
 */
export declare function rebuildFts5Index(nativeDb: DatabaseSync): void;
/**
 * Unified search across all BRAIN memory tables.
 *
 * Uses FTS5 MATCH for full-text search with BM25 ranking when available,
 * falls back to LIKE queries otherwise.
 *
 * @task T5130
 */
export declare function searchBrain(projectRoot: string, query: string, options?: BrainSearchOptions): Promise<BrainSearchResult>;
/**
 * Reset the cached FTS5 availability flag.
 * Used in tests to force re-detection.
 */
export declare function resetFts5Cache(): void;
/**
 * The RRF smoothing constant (research-proven at 60).
 *
 * Balances noise vs. signal: small values amplify top-rank differences;
 * large values compress ranks toward a flat distribution. 60 is the
 * standard value from Cormack, Clarke & Buettcher (SIGIR 2009).
 */
export declare const RRF_K = 60;
/** A single ranked hit from one retrieval source before fusion. */
export interface RrfHit {
    id: string;
    type: string;
    title: string;
    text: string;
}
/** Fused result produced by reciprocalRankFusion. */
export interface RrfResult {
    id: string;
    /** Combined RRF score: sum of 1/(rank+RRF_K) across all source lists. */
    rrfScore: number;
    type: string;
    title: string;
    text: string;
    /** Which retrieval sources contributed to this result. */
    sources: Array<'fts' | 'vec' | 'graph'>;
    /** BM25-derived FTS rank (0-based) — undefined if not in FTS results. */
    ftsRank?: number;
    /** Vector distance rank (0-based) — undefined if not in vector results. */
    vecRank?: number;
}
/**
 * Fuse ranked lists from multiple retrieval sources using Reciprocal Rank Fusion.
 *
 * Implements the RRF algorithm from Cormack, Clarke & Buettcher (SIGIR 2009):
 *
 *   score(d) = Σ 1 / (k + rank(d, list))  for each list containing d
 *
 * where k=60 is the research-proven smoothing constant.
 *
 * Properties:
 * - Rank-based: actual scores from each source are ignored (only rank matters).
 * - Additive: items appearing in multiple lists accumulate higher scores.
 * - Robust: the +60 constant prevents rank-1 items from dominating.
 *
 * @param sources - Named arrays of ranked hits (order = rank, index 0 = best)
 * @param k - RRF smoothing constant (default: RRF_K = 60)
 * @returns Array of fused results sorted by rrfScore descending
 *
 * @example
 * ```ts
 * const fused = reciprocalRankFusion([
 *   { source: 'fts', hits: ftsHits },
 *   { source: 'vec', hits: vecHits },
 * ]);
 * ```
 */
export declare function reciprocalRankFusion(sources: Array<{
    source: 'fts' | 'vec' | 'graph';
    hits: RrfHit[];
}>, k?: number): RrfResult[];
/** Result from hybridSearch combining multiple search signals. */
export interface HybridResult {
    id: string;
    /** RRF-fused score: sum of 1/(rank+60) across all source lists. */
    score: number;
    type: string;
    title: string;
    text: string;
    sources: Array<'fts' | 'vec' | 'graph'>;
    /** Raw FTS rank (0-based) for transparency — undefined if FTS did not return this item. */
    ftsRank?: number;
    /** Raw vector rank (0-based) for transparency — undefined if vector did not return this item. */
    vecRank?: number;
}
/** Options for hybridSearch. */
export interface HybridSearchOptions {
    limit?: number;
    /**
     * RRF smoothing constant k. Default: 60 (research-proven).
     * Larger k flattens rank differences; smaller k amplifies top-rank advantage.
     */
    rrfK?: number;
}
/**
 * Hybrid search across FTS5, vector similarity, and graph neighbors using
 * Reciprocal Rank Fusion (RRF) for result combination.
 *
 * Algorithm:
 * 1. Run FTS5 search and vector similarity search in parallel.
 * 2. Optionally expand via graph neighbors (best-effort).
 * 3. Fuse all ranked lists with RRF: score = Σ 1/(rank+60).
 * 4. Return top-N sorted by fused RRF score.
 *
 * Graceful degradation: vector and graph sources are silently skipped when
 * unavailable — RRF naturally handles partial source lists.
 *
 * @param query - Search query text
 * @param projectRoot - Project root directory
 * @param options - Limit and RRF tuning
 * @returns Array of hybrid results ranked by RRF score descending
 */
export declare function hybridSearch(query: string, projectRoot: string, options?: HybridSearchOptions): Promise<HybridResult[]>;
//# sourceMappingURL=brain-search.d.ts.map