/** * Conversation segmentation — detects topic boundaries between consecutive messages * and groups messages into segments for cluster retrieval. * * Boundaries are detected by comparing embeddings of consecutive messages. * When cosine distance exceeds a threshold, a new segment starts. */ /** * A detected segment boundary — marks where a new topic starts. */ export interface SegmentBoundary { /** Message index where the new segment starts */ messageIndex: number; /** ISO timestamp of boundary detection */ timestamp: string; /** Cosine distance from the previous message that triggered the boundary */ distanceFromPrevious: number; } /** * A segment is a contiguous range of message indices sharing a topic. */ export interface Segment { /** First message index (inclusive) */ start: number; /** Last message index (inclusive) */ end: number; } /** * Get the segments file path for a thread. */ export declare function getSegmentsPath(threadPath: string): string; /** * Load segment boundaries from disk. */ export declare function loadSegmentBoundaries(threadPath: string): Promise; /** * Save segment boundaries to disk (atomic write). */ export declare function saveSegmentBoundaries(threadPath: string, boundaries: SegmentBoundary[]): Promise; /** * Detect whether a new message starts a new segment. * Compares the embedding of the new message to the previous message's embedding. * * Returns the boundary if a topic shift is detected, or null if same segment. */ export declare function detectBoundary(messageIndex: number, messageContent: string, currentEmbedding: number[], previousEmbedding: number[]): SegmentBoundary | null; /** * Build segment ranges from boundaries. * Given boundaries at indices [10, 25, 50] and totalMessages = 70: * segments = [{0,9}, {10,24}, {25,49}, {50,69}] */ export declare function buildSegments(boundaries: SegmentBoundary[], totalMessages: number): Segment[]; /** * Find which segment a message belongs to. * Returns the segment range, or null if no segments exist. */ export declare function findSegmentForMessage(messageIndex: number, segments: Segment[]): Segment | null; /** * Run catch-up segmentation for messages that were added without boundary detection. * Scans from `startIndex` to `endIndex` (inclusive), using provided embeddings. * * @param existingBoundaries - Already-known boundaries * @param embeddings - Map of messageId → embedding vector * @param messages - All messages in order (index = position) * @param startIndex - First message index to check * @param endIndex - Last message index to check (inclusive) * @returns New boundaries detected during catch-up */ export declare function catchUpSegmentation(existingBoundaries: SegmentBoundary[], embeddings: Map, messages: Array<{ id: string; content: string; }>, startIndex: number, endIndex: number): SegmentBoundary[]; //# sourceMappingURL=segments.d.ts.map