raggrep 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,3 +16,5 @@ export type { FileIntrospection, ProjectStructure, Project, ProjectType, Scope,
16
16
  export type { FileConvention, ConventionCategory, FrameworkConventions, ConventionMatch, } from "./conventions";
17
17
  export type { LiteralType, LiteralMatchType, LiteralConfidence, LiteralDetectionMethod, ExtractedLiteral, DetectedLiteral, QueryLiteralParseResult, LiteralMatch, LiteralIndexEntry, LiteralIndexData, } from "./literal";
18
18
  export { LITERAL_SCORING } from "./literal";
19
+ export type { SynonymGrade, Synonym, SynonymEntry, Lexicon, ExpandedTerm, ExpandedQuery, ExpansionOptions, } from "./lexicon";
20
+ export { DEFAULT_EXPANSION_OPTIONS, EXPANSION_WEIGHTS } from "./lexicon";
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Lexicon Types
3
+ *
4
+ * Type definitions for Structured Semantic Expansion (SSE).
5
+ * SSE improves search recall by expanding query terms with domain-specific synonyms.
6
+ *
7
+ * This is a pure domain entity with no external dependencies.
8
+ */
9
+ /**
10
+ * Correlation grade for synonyms.
11
+ * Determines how much weight a synonym contributes to scoring.
12
+ *
13
+ * - strong: Near-equivalent concepts (function ↔ method)
14
+ * - moderate: Related but distinct (function ↔ handler)
15
+ * - weak: Loosely associated (auth ↔ security)
16
+ */
17
+ export type SynonymGrade = "strong" | "moderate" | "weak";
18
+ /**
19
+ * A single synonym with its correlation grade.
20
+ */
21
+ export interface Synonym {
22
+ /** The synonym term */
23
+ term: string;
24
+ /** Correlation strength with the parent term */
25
+ grade: SynonymGrade;
26
+ }
27
+ /**
28
+ * A synonym entry in the lexicon.
29
+ */
30
+ export interface SynonymEntry {
31
+ /** The canonical term */
32
+ term: string;
33
+ /** Synonyms with their correlation grades */
34
+ synonyms: Synonym[];
35
+ /** Optional context restriction (e.g., "typescript", "database") */
36
+ context?: string;
37
+ }
38
+ /**
39
+ * The lexicon containing all synonym mappings.
40
+ */
41
+ export interface Lexicon {
42
+ /** Version for compatibility checking */
43
+ version: string;
44
+ /** All synonym entries */
45
+ entries: SynonymEntry[];
46
+ /** Optional module-specific overrides */
47
+ moduleOverrides?: Record<string, SynonymEntry[]>;
48
+ }
49
+ /**
50
+ * An expanded term with weight information.
51
+ */
52
+ export interface ExpandedTerm {
53
+ /** The term (original or synonym) */
54
+ term: string;
55
+ /** Weight for scoring (1.0 for original, lower for synonyms) */
56
+ weight: number;
57
+ /** How this term was derived */
58
+ source: "original" | "strong" | "moderate" | "weak";
59
+ /** The original term this was expanded from (if synonym) */
60
+ expandedFrom?: string;
61
+ }
62
+ /**
63
+ * Result of expanding a query.
64
+ */
65
+ export interface ExpandedQuery {
66
+ /** Original query string */
67
+ originalQuery: string;
68
+ /** Original query terms (tokenized) */
69
+ originalTerms: string[];
70
+ /** All terms including expansions with weights */
71
+ expandedTerms: ExpandedTerm[];
72
+ /** Query string with expansions (for embedding) */
73
+ expandedQueryString: string;
74
+ /** Whether any expansion occurred */
75
+ wasExpanded: boolean;
76
+ }
77
+ /**
78
+ * Options for query expansion.
79
+ */
80
+ export interface ExpansionOptions {
81
+ /** Maximum expansion depth (passes). Default: 1 */
82
+ maxDepth?: number;
83
+ /** Include weak synonyms. Default: true */
84
+ includeWeak?: boolean;
85
+ /** Maximum total terms after expansion. Default: 20 */
86
+ maxTerms?: number;
87
+ /** Minimum term length to expand. Default: 2 */
88
+ minTermLength?: number;
89
+ /** Context filter (only use entries matching this context) */
90
+ context?: string;
91
+ }
92
+ /**
93
+ * Default expansion options.
94
+ */
95
+ export declare const DEFAULT_EXPANSION_OPTIONS: Required<Omit<ExpansionOptions, "context">>;
96
+ /**
97
+ * Weights applied to synonyms by grade.
98
+ */
99
+ export declare const EXPANSION_WEIGHTS: Record<SynonymGrade, number>;
@@ -12,3 +12,4 @@ export { createLineBasedChunks, createSingleChunk, generateChunkId, DEFAULT_CHUN
12
12
  export { parseQueryLiterals } from "./queryLiteralParser";
13
13
  export { extractLiterals, extractLiteralsWithReferences, } from "./literalExtractor";
14
14
  export { calculateLiteralMultiplier, calculateMaxMultiplier, calculateLiteralContribution, applyLiteralBoost, mergeWithLiteralBoost, LITERAL_SCORING_CONSTANTS, type LiteralScoreContribution, type MergeInput, type MergeOutput, } from "./literalScorer";
15
+ export { getSynonyms, expandQuery, DEFAULT_LEXICON, EXPANSION_WEIGHTS, DEFAULT_EXPANSION_OPTIONS, } from "./lexicon";
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Lexicon Service
3
+ *
4
+ * Provides query expansion using domain-specific synonyms.
5
+ * Part of Structured Semantic Expansion (SSE) for improved search recall.
6
+ *
7
+ * This is a pure domain service with no external dependencies.
8
+ */
9
+ import type { Lexicon, Synonym, ExpandedQuery, ExpansionOptions } from "../entities/lexicon";
10
+ import { DEFAULT_EXPANSION_OPTIONS, EXPANSION_WEIGHTS } from "../entities/lexicon";
11
+ /**
12
+ * Default lexicon for programming domain.
13
+ *
14
+ * Contains common synonyms for code-related terms.
15
+ * Grades indicate correlation strength:
16
+ * - strong: Near-equivalent (function ↔ method)
17
+ * - moderate: Related but distinct (function ↔ handler)
18
+ * - weak: Loosely associated (auth ↔ security)
19
+ */
20
+ export declare const DEFAULT_LEXICON: Lexicon;
21
+ /**
22
+ * Get synonyms for a term from the lexicon.
23
+ *
24
+ * @param term - The term to look up
25
+ * @param lexicon - The lexicon to use (defaults to DEFAULT_LEXICON)
26
+ * @returns Array of synonyms with grades, or empty array if not found
27
+ */
28
+ export declare function getSynonyms(term: string, lexicon?: Lexicon): Synonym[];
29
+ /**
30
+ * Expand a query using the lexicon.
31
+ *
32
+ * @param query - The original query string
33
+ * @param lexicon - The lexicon to use (defaults to DEFAULT_LEXICON)
34
+ * @param options - Expansion options
35
+ * @returns Expanded query with weights
36
+ */
37
+ export declare function expandQuery(query: string, lexicon?: Lexicon, options?: ExpansionOptions): ExpandedQuery;
38
+ /**
39
+ * Get expansion weights by grade (re-exported for convenience).
40
+ */
41
+ export { EXPANSION_WEIGHTS };
42
+ /**
43
+ * Get default expansion options (re-exported for convenience).
44
+ */
45
+ export { DEFAULT_EXPANSION_OPTIONS };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Lexicon Service Tests
3
+ *
4
+ * Tests for query expansion using domain-specific synonyms.
5
+ */
6
+ export {};