/** * Relation Extractor * * Extracts semantic relationships between memories using: * 1. Embedding similarity to find candidate pairs * 2. Heuristic rules to classify relation types * * Runs in background after each store_memory call. * Uses rule-based extraction (no LLM dependency) for speed, * with optional LLM refinement when available. */ import { ExtractedRelation } from "@massa-th0th/shared"; import type { MemoryRow } from "../../data/memory/memory-repository.js"; import type { IGraphStore } from "./types.js"; interface ExtractionOptions { /** Max similar memories to compare against */ candidateLimit?: number; /** Min similarity to consider a relation */ similarityThreshold?: number; /** Min confidence to create an edge */ confidenceThreshold?: number; } export declare class RelationExtractor { private embeddingService; private graphStore; constructor(graphStore?: IGraphStore); /** * Extract relations for a newly stored memory. * Called in background after store_memory. * * Steps: * 1. Get embedding of new memory * 2. Find top-N similar existing memories * 3. For each candidate, classify the relation * 4. Create edges for high-confidence relations */ extractRelations(memoryId: string, options?: ExtractionOptions): Promise; /** * Find memories with similar embeddings (brute-force cosine similarity). */ private findSimilarMemories; /** * Classify the relation between two memories using heuristic rules. * * Rules cascade by priority: * 1. SUPERSEDES: same type, high similarity, newer contradicts older * 2. CONTRADICTS: contradiction signals in newer content * 3. RESOLVES: resolution signals + related bug/decision * 4. DERIVED_FROM: derivation signals or same topic chain * 5. SUPPORTS: support signals or reinforcing pattern * 6. RELATES_TO: high similarity but no specific relation */ classifyRelation(newMemory: MemoryRow, existingMemory: MemoryRow & { similarity: number; }): ExtractedRelation; private loadMemory; private sharesTags; private cosineSimilarity; } export {}; //# sourceMappingURL=relation-extractor.d.ts.map