@liendev/core 0.19.5
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.
- package/README.md +336 -0
- package/dist/config/loader.d.ts +12 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +46 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/merge.d.ts +20 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +71 -0
- package/dist/config/merge.js.map +1 -0
- package/dist/config/migration-manager.d.ts +46 -0
- package/dist/config/migration-manager.d.ts.map +1 -0
- package/dist/config/migration-manager.js +119 -0
- package/dist/config/migration-manager.js.map +1 -0
- package/dist/config/migration.d.ts +20 -0
- package/dist/config/migration.d.ts.map +1 -0
- package/dist/config/migration.js +155 -0
- package/dist/config/migration.js.map +1 -0
- package/dist/config/schema.d.ts +101 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +58 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/service.d.ts +122 -0
- package/dist/config/service.d.ts.map +1 -0
- package/dist/config/service.js +477 -0
- package/dist/config/service.js.map +1 -0
- package/dist/constants.d.ts +20 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +43 -0
- package/dist/constants.js.map +1 -0
- package/dist/embeddings/cache.d.ts +45 -0
- package/dist/embeddings/cache.d.ts.map +1 -0
- package/dist/embeddings/cache.js +109 -0
- package/dist/embeddings/cache.js.map +1 -0
- package/dist/embeddings/local.d.ts +10 -0
- package/dist/embeddings/local.d.ts.map +1 -0
- package/dist/embeddings/local.js +63 -0
- package/dist/embeddings/local.js.map +1 -0
- package/dist/embeddings/types.d.ts +9 -0
- package/dist/embeddings/types.d.ts.map +1 -0
- package/dist/embeddings/types.js +5 -0
- package/dist/embeddings/types.js.map +1 -0
- package/dist/errors/codes.d.ts +18 -0
- package/dist/errors/codes.d.ts.map +1 -0
- package/dist/errors/codes.js +25 -0
- package/dist/errors/codes.js.map +1 -0
- package/dist/errors/index.d.ts +85 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +134 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/frameworks/detector-service.d.ts +59 -0
- package/dist/frameworks/detector-service.d.ts.map +1 -0
- package/dist/frameworks/detector-service.js +219 -0
- package/dist/frameworks/detector-service.js.map +1 -0
- package/dist/frameworks/laravel/config.d.ts +6 -0
- package/dist/frameworks/laravel/config.d.ts.map +1 -0
- package/dist/frameworks/laravel/config.js +68 -0
- package/dist/frameworks/laravel/config.js.map +1 -0
- package/dist/frameworks/laravel/detector.d.ts +6 -0
- package/dist/frameworks/laravel/detector.d.ts.map +1 -0
- package/dist/frameworks/laravel/detector.js +96 -0
- package/dist/frameworks/laravel/detector.js.map +1 -0
- package/dist/frameworks/nodejs/config.d.ts +6 -0
- package/dist/frameworks/nodejs/config.d.ts.map +1 -0
- package/dist/frameworks/nodejs/config.js +57 -0
- package/dist/frameworks/nodejs/config.js.map +1 -0
- package/dist/frameworks/nodejs/detector.d.ts +6 -0
- package/dist/frameworks/nodejs/detector.d.ts.map +1 -0
- package/dist/frameworks/nodejs/detector.js +77 -0
- package/dist/frameworks/nodejs/detector.js.map +1 -0
- package/dist/frameworks/php/config.d.ts +6 -0
- package/dist/frameworks/php/config.d.ts.map +1 -0
- package/dist/frameworks/php/config.js +53 -0
- package/dist/frameworks/php/config.js.map +1 -0
- package/dist/frameworks/php/detector.d.ts +7 -0
- package/dist/frameworks/php/detector.d.ts.map +1 -0
- package/dist/frameworks/php/detector.js +101 -0
- package/dist/frameworks/php/detector.js.map +1 -0
- package/dist/frameworks/registry.d.ts +20 -0
- package/dist/frameworks/registry.d.ts.map +1 -0
- package/dist/frameworks/registry.js +38 -0
- package/dist/frameworks/registry.js.map +1 -0
- package/dist/frameworks/shopify/config.d.ts +6 -0
- package/dist/frameworks/shopify/config.d.ts.map +1 -0
- package/dist/frameworks/shopify/config.js +50 -0
- package/dist/frameworks/shopify/config.js.map +1 -0
- package/dist/frameworks/shopify/detector.d.ts +6 -0
- package/dist/frameworks/shopify/detector.d.ts.map +1 -0
- package/dist/frameworks/shopify/detector.js +103 -0
- package/dist/frameworks/shopify/detector.js.map +1 -0
- package/dist/frameworks/types.d.ts +51 -0
- package/dist/frameworks/types.d.ts.map +1 -0
- package/dist/frameworks/types.js +21 -0
- package/dist/frameworks/types.js.map +1 -0
- package/dist/git/tracker.d.ts +56 -0
- package/dist/git/tracker.d.ts.map +1 -0
- package/dist/git/tracker.js +189 -0
- package/dist/git/tracker.js.map +1 -0
- package/dist/git/utils.d.ts +60 -0
- package/dist/git/utils.d.ts.map +1 -0
- package/dist/git/utils.js +152 -0
- package/dist/git/utils.js.map +1 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/ast/chunker.d.ts +28 -0
- package/dist/indexer/ast/chunker.d.ts.map +1 -0
- package/dist/indexer/ast/chunker.js +268 -0
- package/dist/indexer/ast/chunker.js.map +1 -0
- package/dist/indexer/ast/complexity/cognitive.d.ts +16 -0
- package/dist/indexer/ast/complexity/cognitive.d.ts.map +1 -0
- package/dist/indexer/ast/complexity/cognitive.js +106 -0
- package/dist/indexer/ast/complexity/cognitive.js.map +1 -0
- package/dist/indexer/ast/complexity/cyclomatic.d.ts +12 -0
- package/dist/indexer/ast/complexity/cyclomatic.d.ts.map +1 -0
- package/dist/indexer/ast/complexity/cyclomatic.js +61 -0
- package/dist/indexer/ast/complexity/cyclomatic.js.map +1 -0
- package/dist/indexer/ast/complexity/halstead.d.ts +55 -0
- package/dist/indexer/ast/complexity/halstead.d.ts.map +1 -0
- package/dist/indexer/ast/complexity/halstead.js +290 -0
- package/dist/indexer/ast/complexity/halstead.js.map +1 -0
- package/dist/indexer/ast/complexity/index.d.ts +13 -0
- package/dist/indexer/ast/complexity/index.d.ts.map +1 -0
- package/dist/indexer/ast/complexity/index.js +12 -0
- package/dist/indexer/ast/complexity/index.js.map +1 -0
- package/dist/indexer/ast/parser.d.ts +27 -0
- package/dist/indexer/ast/parser.d.ts.map +1 -0
- package/dist/indexer/ast/parser.js +103 -0
- package/dist/indexer/ast/parser.js.map +1 -0
- package/dist/indexer/ast/symbols.d.ts +17 -0
- package/dist/indexer/ast/symbols.d.ts.map +1 -0
- package/dist/indexer/ast/symbols.js +265 -0
- package/dist/indexer/ast/symbols.js.map +1 -0
- package/dist/indexer/ast/traversers/index.d.ts +19 -0
- package/dist/indexer/ast/traversers/index.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/index.js +42 -0
- package/dist/indexer/ast/traversers/index.js.map +1 -0
- package/dist/indexer/ast/traversers/php.d.ts +21 -0
- package/dist/indexer/ast/traversers/php.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/php.js +67 -0
- package/dist/indexer/ast/traversers/php.js.map +1 -0
- package/dist/indexer/ast/traversers/python.d.ts +28 -0
- package/dist/indexer/ast/traversers/python.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/python.js +67 -0
- package/dist/indexer/ast/traversers/python.js.map +1 -0
- package/dist/indexer/ast/traversers/types.d.ts +98 -0
- package/dist/indexer/ast/traversers/types.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/types.js +2 -0
- package/dist/indexer/ast/traversers/types.js.map +1 -0
- package/dist/indexer/ast/traversers/typescript.d.ts +29 -0
- package/dist/indexer/ast/traversers/typescript.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/typescript.js +88 -0
- package/dist/indexer/ast/traversers/typescript.js.map +1 -0
- package/dist/indexer/ast/types.d.ts +59 -0
- package/dist/indexer/ast/types.d.ts.map +1 -0
- package/dist/indexer/ast/types.js +2 -0
- package/dist/indexer/ast/types.js.map +1 -0
- package/dist/indexer/change-detector.d.ts +17 -0
- package/dist/indexer/change-detector.d.ts.map +1 -0
- package/dist/indexer/change-detector.js +207 -0
- package/dist/indexer/change-detector.js.map +1 -0
- package/dist/indexer/chunk-batch-processor.d.ts +103 -0
- package/dist/indexer/chunk-batch-processor.d.ts.map +1 -0
- package/dist/indexer/chunk-batch-processor.js +179 -0
- package/dist/indexer/chunk-batch-processor.js.map +1 -0
- package/dist/indexer/chunker.d.ts +10 -0
- package/dist/indexer/chunker.d.ts.map +1 -0
- package/dist/indexer/chunker.js +96 -0
- package/dist/indexer/chunker.js.map +1 -0
- package/dist/indexer/dependency-analyzer.d.ts +60 -0
- package/dist/indexer/dependency-analyzer.d.ts.map +1 -0
- package/dist/indexer/dependency-analyzer.js +261 -0
- package/dist/indexer/dependency-analyzer.js.map +1 -0
- package/dist/indexer/incremental.d.ts +47 -0
- package/dist/indexer/incremental.d.ts.map +1 -0
- package/dist/indexer/incremental.js +284 -0
- package/dist/indexer/incremental.js.map +1 -0
- package/dist/indexer/index.d.ts +80 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +364 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/indexer/json-template-chunker.d.ts +9 -0
- package/dist/indexer/json-template-chunker.d.ts.map +1 -0
- package/dist/indexer/json-template-chunker.js +83 -0
- package/dist/indexer/json-template-chunker.js.map +1 -0
- package/dist/indexer/liquid-chunker.d.ts +13 -0
- package/dist/indexer/liquid-chunker.d.ts.map +1 -0
- package/dist/indexer/liquid-chunker.js +272 -0
- package/dist/indexer/liquid-chunker.js.map +1 -0
- package/dist/indexer/manifest.d.ts +122 -0
- package/dist/indexer/manifest.d.ts.map +1 -0
- package/dist/indexer/manifest.js +262 -0
- package/dist/indexer/manifest.js.map +1 -0
- package/dist/indexer/progress-tracker.d.ts +35 -0
- package/dist/indexer/progress-tracker.d.ts.map +1 -0
- package/dist/indexer/progress-tracker.js +33 -0
- package/dist/indexer/progress-tracker.js.map +1 -0
- package/dist/indexer/scanner.d.ts +16 -0
- package/dist/indexer/scanner.d.ts.map +1 -0
- package/dist/indexer/scanner.js +159 -0
- package/dist/indexer/scanner.js.map +1 -0
- package/dist/indexer/symbol-extractor.d.ts +18 -0
- package/dist/indexer/symbol-extractor.d.ts.map +1 -0
- package/dist/indexer/symbol-extractor.js +351 -0
- package/dist/indexer/symbol-extractor.js.map +1 -0
- package/dist/indexer/types.d.ts +34 -0
- package/dist/indexer/types.d.ts.map +1 -0
- package/dist/indexer/types.js +2 -0
- package/dist/indexer/types.js.map +1 -0
- package/dist/insights/complexity-analyzer.d.ts +82 -0
- package/dist/insights/complexity-analyzer.d.ts.map +1 -0
- package/dist/insights/complexity-analyzer.js +356 -0
- package/dist/insights/complexity-analyzer.js.map +1 -0
- package/dist/insights/formatters/index.d.ts +11 -0
- package/dist/insights/formatters/index.d.ts.map +1 -0
- package/dist/insights/formatters/index.js +20 -0
- package/dist/insights/formatters/index.js.map +1 -0
- package/dist/insights/formatters/json.d.ts +7 -0
- package/dist/insights/formatters/json.d.ts.map +1 -0
- package/dist/insights/formatters/json.js +14 -0
- package/dist/insights/formatters/json.js.map +1 -0
- package/dist/insights/formatters/sarif.d.ts +6 -0
- package/dist/insights/formatters/sarif.d.ts.map +1 -0
- package/dist/insights/formatters/sarif.js +113 -0
- package/dist/insights/formatters/sarif.js.map +1 -0
- package/dist/insights/formatters/text.d.ts +6 -0
- package/dist/insights/formatters/text.d.ts.map +1 -0
- package/dist/insights/formatters/text.js +154 -0
- package/dist/insights/formatters/text.js.map +1 -0
- package/dist/insights/types.d.ts +73 -0
- package/dist/insights/types.d.ts.map +1 -0
- package/dist/insights/types.js +9 -0
- package/dist/insights/types.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/path-matching.d.ts +69 -0
- package/dist/utils/path-matching.d.ts.map +1 -0
- package/dist/utils/path-matching.js +123 -0
- package/dist/utils/path-matching.js.map +1 -0
- package/dist/utils/result.d.ts +65 -0
- package/dist/utils/result.d.ts.map +1 -0
- package/dist/utils/result.js +67 -0
- package/dist/utils/result.js.map +1 -0
- package/dist/utils/version.d.ts +22 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +28 -0
- package/dist/utils/version.js.map +1 -0
- package/dist/vectordb/batch-insert.d.ts +14 -0
- package/dist/vectordb/batch-insert.d.ts.map +1 -0
- package/dist/vectordb/batch-insert.js +185 -0
- package/dist/vectordb/batch-insert.js.map +1 -0
- package/dist/vectordb/boosting/composer.d.ts +51 -0
- package/dist/vectordb/boosting/composer.d.ts.map +1 -0
- package/dist/vectordb/boosting/composer.js +65 -0
- package/dist/vectordb/boosting/composer.js.map +1 -0
- package/dist/vectordb/boosting/index.d.ts +22 -0
- package/dist/vectordb/boosting/index.d.ts.map +1 -0
- package/dist/vectordb/boosting/index.js +22 -0
- package/dist/vectordb/boosting/index.js.map +1 -0
- package/dist/vectordb/boosting/strategies.d.ts +40 -0
- package/dist/vectordb/boosting/strategies.d.ts.map +1 -0
- package/dist/vectordb/boosting/strategies.js +174 -0
- package/dist/vectordb/boosting/strategies.js.map +1 -0
- package/dist/vectordb/boosting/types.d.ts +20 -0
- package/dist/vectordb/boosting/types.d.ts.map +1 -0
- package/dist/vectordb/boosting/types.js +2 -0
- package/dist/vectordb/boosting/types.js.map +1 -0
- package/dist/vectordb/intent-classifier.d.ts +99 -0
- package/dist/vectordb/intent-classifier.d.ts.map +1 -0
- package/dist/vectordb/intent-classifier.js +193 -0
- package/dist/vectordb/intent-classifier.js.map +1 -0
- package/dist/vectordb/lancedb.d.ts +45 -0
- package/dist/vectordb/lancedb.d.ts.map +1 -0
- package/dist/vectordb/lancedb.js +203 -0
- package/dist/vectordb/lancedb.js.map +1 -0
- package/dist/vectordb/maintenance.d.ts +18 -0
- package/dist/vectordb/maintenance.d.ts.map +1 -0
- package/dist/vectordb/maintenance.js +87 -0
- package/dist/vectordb/maintenance.js.map +1 -0
- package/dist/vectordb/query.d.ts +34 -0
- package/dist/vectordb/query.d.ts.map +1 -0
- package/dist/vectordb/query.js +303 -0
- package/dist/vectordb/query.js.map +1 -0
- package/dist/vectordb/relevance.d.ts +15 -0
- package/dist/vectordb/relevance.d.ts.map +1 -0
- package/dist/vectordb/relevance.js +19 -0
- package/dist/vectordb/relevance.js.map +1 -0
- package/dist/vectordb/types.d.ts +29 -0
- package/dist/vectordb/types.d.ts.map +1 -0
- package/dist/vectordb/types.js +2 -0
- package/dist/vectordb/types.js.map +1 -0
- package/dist/vectordb/version.d.ts +16 -0
- package/dist/vectordb/version.d.ts.map +1 -0
- package/dist/vectordb/version.js +40 -0
- package/dist/vectordb/version.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { QueryIntent } from '../intent-classifier.js';
|
|
3
|
+
/**
|
|
4
|
+
* File type detection helpers
|
|
5
|
+
*/
|
|
6
|
+
function isDocumentationFile(filepath) {
|
|
7
|
+
const lower = filepath.toLowerCase();
|
|
8
|
+
const filename = path.basename(filepath).toLowerCase();
|
|
9
|
+
if (filename.startsWith('readme'))
|
|
10
|
+
return true;
|
|
11
|
+
if (filename.startsWith('changelog'))
|
|
12
|
+
return true;
|
|
13
|
+
if (filename.endsWith('.md') || filename.endsWith('.mdx') || filename.endsWith('.markdown')) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (lower.includes('/docs/') ||
|
|
17
|
+
lower.includes('/documentation/') ||
|
|
18
|
+
lower.includes('/wiki/') ||
|
|
19
|
+
lower.includes('/.github/')) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (lower.includes('architecture') ||
|
|
23
|
+
lower.includes('workflow') ||
|
|
24
|
+
lower.includes('/flow/')) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function isTestFile(filepath) {
|
|
30
|
+
const lower = filepath.toLowerCase();
|
|
31
|
+
if (lower.includes('/test/') ||
|
|
32
|
+
lower.includes('/tests/') ||
|
|
33
|
+
lower.includes('/__tests__/')) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (lower.includes('.test.') ||
|
|
37
|
+
lower.includes('.spec.') ||
|
|
38
|
+
lower.includes('_test.') ||
|
|
39
|
+
lower.includes('_spec.')) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
function isUtilityFile(filepath) {
|
|
45
|
+
const lower = filepath.toLowerCase();
|
|
46
|
+
if (lower.includes('/utils/') ||
|
|
47
|
+
lower.includes('/utilities/') ||
|
|
48
|
+
lower.includes('/helpers/') ||
|
|
49
|
+
lower.includes('/lib/')) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (lower.includes('.util.') ||
|
|
53
|
+
lower.includes('.helper.') ||
|
|
54
|
+
lower.includes('-util.') ||
|
|
55
|
+
lower.includes('-helper.')) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Boosting Strategies
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Boosts relevance based on path segment matching.
|
|
65
|
+
* Files with query tokens in their path are boosted.
|
|
66
|
+
*/
|
|
67
|
+
export class PathBoostingStrategy {
|
|
68
|
+
name = 'path-matching';
|
|
69
|
+
apply(query, filepath, baseScore) {
|
|
70
|
+
const queryTokens = query.toLowerCase().split(/\s+/);
|
|
71
|
+
const pathSegments = filepath.toLowerCase().split('/');
|
|
72
|
+
let boostFactor = 1.0;
|
|
73
|
+
for (const token of queryTokens) {
|
|
74
|
+
if (token.length <= 2)
|
|
75
|
+
continue;
|
|
76
|
+
if (pathSegments.some(seg => seg.includes(token))) {
|
|
77
|
+
boostFactor *= 0.9; // Reduce distance = increase relevance
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return baseScore * boostFactor;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Boosts relevance based on filename matching.
|
|
85
|
+
* Files with query tokens in their filename are strongly boosted.
|
|
86
|
+
*/
|
|
87
|
+
export class FilenameBoostingStrategy {
|
|
88
|
+
name = 'filename-matching';
|
|
89
|
+
apply(query, filepath, baseScore) {
|
|
90
|
+
const filename = path.basename(filepath, path.extname(filepath)).toLowerCase();
|
|
91
|
+
const queryTokens = query.toLowerCase().split(/\s+/);
|
|
92
|
+
let boostFactor = 1.0;
|
|
93
|
+
for (const token of queryTokens) {
|
|
94
|
+
if (token.length <= 2)
|
|
95
|
+
continue;
|
|
96
|
+
if (filename === token) {
|
|
97
|
+
boostFactor *= 0.70; // Strong boost for exact match
|
|
98
|
+
}
|
|
99
|
+
else if (filename.includes(token)) {
|
|
100
|
+
boostFactor *= 0.80; // Moderate boost for partial match
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return baseScore * boostFactor;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Boosts relevance based on file type and query intent.
|
|
108
|
+
* Different file types are boosted for different query intents.
|
|
109
|
+
*
|
|
110
|
+
* Note: This strategy focuses on file-type-specific boosting (test files,
|
|
111
|
+
* documentation files, utility files, etc.). Path and filename boosting
|
|
112
|
+
* are handled separately by PathBoostingStrategy and FilenameBoostingStrategy
|
|
113
|
+
* in the BoostingComposer to avoid double-boosting.
|
|
114
|
+
*/
|
|
115
|
+
export class FileTypeBoostingStrategy {
|
|
116
|
+
intent;
|
|
117
|
+
name = 'file-type';
|
|
118
|
+
constructor(intent) {
|
|
119
|
+
this.intent = intent;
|
|
120
|
+
}
|
|
121
|
+
apply(query, filepath, baseScore) {
|
|
122
|
+
switch (this.intent) {
|
|
123
|
+
case QueryIntent.LOCATION:
|
|
124
|
+
return this.applyLocationBoosting(query, filepath, baseScore);
|
|
125
|
+
case QueryIntent.CONCEPTUAL:
|
|
126
|
+
return this.applyConceptualBoosting(query, filepath, baseScore);
|
|
127
|
+
case QueryIntent.IMPLEMENTATION:
|
|
128
|
+
return this.applyImplementationBoosting(query, filepath, baseScore);
|
|
129
|
+
default:
|
|
130
|
+
return baseScore;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
applyLocationBoosting(_query, filepath, score) {
|
|
134
|
+
// Note: Path and filename boosting are handled by PathBoostingStrategy and
|
|
135
|
+
// FilenameBoostingStrategy in the composer. This method only handles
|
|
136
|
+
// file-type-specific boosting for location queries.
|
|
137
|
+
// Slightly deprioritize test files (users want implementation location, not tests)
|
|
138
|
+
if (isTestFile(filepath)) {
|
|
139
|
+
score *= 1.10;
|
|
140
|
+
}
|
|
141
|
+
return score;
|
|
142
|
+
}
|
|
143
|
+
applyConceptualBoosting(_query, filepath, score) {
|
|
144
|
+
// Note: Path and filename boosting are handled by PathBoostingStrategy and
|
|
145
|
+
// FilenameBoostingStrategy in the composer. This method only handles
|
|
146
|
+
// file-type-specific boosting for conceptual queries.
|
|
147
|
+
// Strong boost for documentation files
|
|
148
|
+
if (isDocumentationFile(filepath)) {
|
|
149
|
+
score *= 0.65;
|
|
150
|
+
const lower = filepath.toLowerCase();
|
|
151
|
+
if (lower.includes('architecture') ||
|
|
152
|
+
lower.includes('workflow') ||
|
|
153
|
+
lower.includes('flow')) {
|
|
154
|
+
score *= 0.90; // Extra boost for architectural docs
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Slight boost for utility files (often contain reusable logic)
|
|
158
|
+
if (isUtilityFile(filepath)) {
|
|
159
|
+
score *= 0.95;
|
|
160
|
+
}
|
|
161
|
+
return score;
|
|
162
|
+
}
|
|
163
|
+
applyImplementationBoosting(_query, filepath, score) {
|
|
164
|
+
// Note: Path and filename boosting are handled by PathBoostingStrategy and
|
|
165
|
+
// FilenameBoostingStrategy in the composer. This method only handles
|
|
166
|
+
// file-type-specific boosting for implementation queries.
|
|
167
|
+
// Slightly deprioritize test files (user wants implementation, not tests)
|
|
168
|
+
if (isTestFile(filepath)) {
|
|
169
|
+
score *= 1.10;
|
|
170
|
+
}
|
|
171
|
+
return score;
|
|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,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAC9B,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAC1B,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EACtB,CAAC;gBACD,KAAK,IAAI,IAAI,CAAC,CAAC,qCAAqC;YACtD,CAAC;QACH,CAAC;QAED,gEAAgE;QAChE,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,KAAK,IAAI,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,2BAA2B,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAa;QACjF,2EAA2E;QAC3E,qEAAqE;QACrE,0DAA0D;QAE1D,0EAA0E;QAC1E,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzB,KAAK,IAAI,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boosting strategy interface.
|
|
3
|
+
*
|
|
4
|
+
* Each strategy applies a specific relevance boosting technique
|
|
5
|
+
* to search results based on file characteristics.
|
|
6
|
+
*/
|
|
7
|
+
export interface BoostingStrategy {
|
|
8
|
+
/** Name of the strategy (for debugging/logging) */
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* Apply the boosting strategy to a score.
|
|
12
|
+
*
|
|
13
|
+
* @param query - The search query string
|
|
14
|
+
* @param filepath - The file path being scored
|
|
15
|
+
* @param baseScore - The base relevance score from vector similarity
|
|
16
|
+
* @returns The boosted score (lower is better, following LanceDB distance metric)
|
|
17
|
+
*/
|
|
18
|
+
apply(query: string, filepath: string, baseScore: number): number;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/vectordb/boosting/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/vectordb/boosting/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Intent Classification
|
|
3
|
+
*
|
|
4
|
+
* Classifies user search queries into three categories to apply
|
|
5
|
+
* appropriate relevance boosting strategies:
|
|
6
|
+
*
|
|
7
|
+
* - LOCATION: "Where is X?" - User wants to find specific files/code
|
|
8
|
+
* - CONCEPTUAL: "How does X work?" - User wants to understand concepts
|
|
9
|
+
* - IMPLEMENTATION: "How is X implemented?" - User wants implementation details
|
|
10
|
+
*
|
|
11
|
+
* Examples:
|
|
12
|
+
* - "where is the auth handler" → LOCATION
|
|
13
|
+
* - "how does authentication work" → CONCEPTUAL
|
|
14
|
+
* - "how is authentication implemented" → IMPLEMENTATION
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Query intent types for semantic search
|
|
18
|
+
*/
|
|
19
|
+
export declare enum QueryIntent {
|
|
20
|
+
/** User wants to locate specific files or code (e.g., "where is X") */
|
|
21
|
+
LOCATION = "location",
|
|
22
|
+
/** User wants to understand concepts/processes (e.g., "how does X work") */
|
|
23
|
+
CONCEPTUAL = "conceptual",
|
|
24
|
+
/** User wants implementation details (e.g., "how is X implemented") */
|
|
25
|
+
IMPLEMENTATION = "implementation"
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Intent classification rule with patterns and priority
|
|
29
|
+
*/
|
|
30
|
+
export interface IntentRule {
|
|
31
|
+
intent: QueryIntent;
|
|
32
|
+
patterns: RegExp[];
|
|
33
|
+
priority: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Classifies a search query into one of three intent categories.
|
|
37
|
+
*
|
|
38
|
+
* Uses data-driven pattern matching to detect query intent.
|
|
39
|
+
* Rules are checked in priority order, with the first match winning.
|
|
40
|
+
*
|
|
41
|
+
* @param query - The search query string
|
|
42
|
+
* @returns The detected query intent (defaults to IMPLEMENTATION)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* classifyQueryIntent("where is the user controller") // → LOCATION
|
|
46
|
+
* classifyQueryIntent("how does authentication work") // → CONCEPTUAL
|
|
47
|
+
* classifyQueryIntent("how is the API implemented") // → IMPLEMENTATION
|
|
48
|
+
*/
|
|
49
|
+
export declare function classifyQueryIntent(query: string): QueryIntent;
|
|
50
|
+
/**
|
|
51
|
+
* Add a custom intent rule (useful for testing or extensions).
|
|
52
|
+
*
|
|
53
|
+
* Returns a cleanup function that removes the added rule.
|
|
54
|
+
* This prevents test pollution and allows proper cleanup.
|
|
55
|
+
*
|
|
56
|
+
* @param rule - The intent rule to add
|
|
57
|
+
* @returns A cleanup function that removes the added rule
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const cleanup = addIntentRule({
|
|
61
|
+
* intent: QueryIntent.LOCATION,
|
|
62
|
+
* priority: 4,
|
|
63
|
+
* patterns: [/custom pattern/]
|
|
64
|
+
* });
|
|
65
|
+
* // ... use the rule ...
|
|
66
|
+
* cleanup(); // removes the rule
|
|
67
|
+
*/
|
|
68
|
+
export declare function addIntentRule(rule: IntentRule): () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Get all patterns for a specific intent (useful for debugging).
|
|
71
|
+
*
|
|
72
|
+
* @param intent - The intent to get patterns for
|
|
73
|
+
* @returns Array of regex patterns for the intent
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const locationPatterns = getPatternsForIntent(QueryIntent.LOCATION);
|
|
77
|
+
*/
|
|
78
|
+
export declare function getPatternsForIntent(intent: QueryIntent): RegExp[];
|
|
79
|
+
/**
|
|
80
|
+
* Get all intent rules (useful for testing/debugging).
|
|
81
|
+
*
|
|
82
|
+
* @returns A copy of the current intent rules
|
|
83
|
+
*/
|
|
84
|
+
export declare function getIntentRules(): IntentRule[];
|
|
85
|
+
/**
|
|
86
|
+
* Reset intent rules to initial state.
|
|
87
|
+
*
|
|
88
|
+
* WARNING: This function is intended for testing only.
|
|
89
|
+
* It removes all custom rules added via addIntentRule().
|
|
90
|
+
* The original built-in rules are preserved.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* // In test cleanup
|
|
94
|
+
* afterEach(() => {
|
|
95
|
+
* resetIntentRules();
|
|
96
|
+
* });
|
|
97
|
+
*/
|
|
98
|
+
export declare function resetIntentRules(): void;
|
|
99
|
+
//# sourceMappingURL=intent-classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-classifier.d.ts","sourceRoot":"","sources":["../../src/vectordb/intent-classifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;GAEG;AACH,oBAAY,WAAW;IACrB,uEAAuE;IACvE,QAAQ,aAAa;IAErB,4EAA4E;IAC5E,UAAU,eAAe;IAEzB,uEAAuE;IACvE,cAAc,mBAAmB;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AA0ED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAe9D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,IAAI,CAe1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,CAIlE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,UAAU,EAAE,CAE7C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAMvC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Intent Classification
|
|
3
|
+
*
|
|
4
|
+
* Classifies user search queries into three categories to apply
|
|
5
|
+
* appropriate relevance boosting strategies:
|
|
6
|
+
*
|
|
7
|
+
* - LOCATION: "Where is X?" - User wants to find specific files/code
|
|
8
|
+
* - CONCEPTUAL: "How does X work?" - User wants to understand concepts
|
|
9
|
+
* - IMPLEMENTATION: "How is X implemented?" - User wants implementation details
|
|
10
|
+
*
|
|
11
|
+
* Examples:
|
|
12
|
+
* - "where is the auth handler" → LOCATION
|
|
13
|
+
* - "how does authentication work" → CONCEPTUAL
|
|
14
|
+
* - "how is authentication implemented" → IMPLEMENTATION
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Query intent types for semantic search
|
|
18
|
+
*/
|
|
19
|
+
export var QueryIntent;
|
|
20
|
+
(function (QueryIntent) {
|
|
21
|
+
/** User wants to locate specific files or code (e.g., "where is X") */
|
|
22
|
+
QueryIntent["LOCATION"] = "location";
|
|
23
|
+
/** User wants to understand concepts/processes (e.g., "how does X work") */
|
|
24
|
+
QueryIntent["CONCEPTUAL"] = "conceptual";
|
|
25
|
+
/** User wants implementation details (e.g., "how is X implemented") */
|
|
26
|
+
QueryIntent["IMPLEMENTATION"] = "implementation";
|
|
27
|
+
})(QueryIntent || (QueryIntent = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Intent classification rules.
|
|
30
|
+
* Rules are checked in priority order (higher priority first).
|
|
31
|
+
*/
|
|
32
|
+
const INTENT_RULES = [
|
|
33
|
+
// LOCATION intent (highest priority - most specific)
|
|
34
|
+
{
|
|
35
|
+
intent: QueryIntent.LOCATION,
|
|
36
|
+
priority: 3,
|
|
37
|
+
patterns: [
|
|
38
|
+
/where\s+(is|are|does|can\s+i\s+find)/,
|
|
39
|
+
/find\s+the\s+/,
|
|
40
|
+
/locate\s+/,
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
// CONCEPTUAL intent (medium priority)
|
|
44
|
+
{
|
|
45
|
+
intent: QueryIntent.CONCEPTUAL,
|
|
46
|
+
priority: 2,
|
|
47
|
+
patterns: [
|
|
48
|
+
/how\s+does\s+.*\s+work/,
|
|
49
|
+
/what\s+(is|are|does)/,
|
|
50
|
+
/explain\s+/,
|
|
51
|
+
/understand\s+/,
|
|
52
|
+
/\b(process|workflow|architecture)\b/,
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
// IMPLEMENTATION intent (low priority - catches "how is X implemented")
|
|
56
|
+
{
|
|
57
|
+
intent: QueryIntent.IMPLEMENTATION,
|
|
58
|
+
priority: 1,
|
|
59
|
+
patterns: [
|
|
60
|
+
/how\s+(is|are)\s+.*\s+(implemented|built|coded)/,
|
|
61
|
+
/implementation\s+of/,
|
|
62
|
+
/source\s+code\s+for/,
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
/**
|
|
67
|
+
* Capture the initial number of built-in rules.
|
|
68
|
+
* This is used by resetIntentRules() to distinguish built-in rules from custom rules.
|
|
69
|
+
*/
|
|
70
|
+
const INITIAL_RULE_COUNT = INTENT_RULES.length;
|
|
71
|
+
/**
|
|
72
|
+
* Cached sorted rules to avoid re-sorting on every query.
|
|
73
|
+
* Invalidated when rules are modified via addIntentRule() or resetIntentRules().
|
|
74
|
+
*/
|
|
75
|
+
let cachedSortedRules = null;
|
|
76
|
+
/**
|
|
77
|
+
* Get sorted rules (cached).
|
|
78
|
+
* Lazy-computes and caches the sorted array on first access.
|
|
79
|
+
*/
|
|
80
|
+
function getSortedRules() {
|
|
81
|
+
if (cachedSortedRules === null) {
|
|
82
|
+
cachedSortedRules = [...INTENT_RULES].sort((a, b) => b.priority - a.priority);
|
|
83
|
+
}
|
|
84
|
+
return cachedSortedRules;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Invalidate the sorted rules cache.
|
|
88
|
+
* Called when rules are modified.
|
|
89
|
+
*/
|
|
90
|
+
function invalidateSortedRulesCache() {
|
|
91
|
+
cachedSortedRules = null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Classifies a search query into one of three intent categories.
|
|
95
|
+
*
|
|
96
|
+
* Uses data-driven pattern matching to detect query intent.
|
|
97
|
+
* Rules are checked in priority order, with the first match winning.
|
|
98
|
+
*
|
|
99
|
+
* @param query - The search query string
|
|
100
|
+
* @returns The detected query intent (defaults to IMPLEMENTATION)
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* classifyQueryIntent("where is the user controller") // → LOCATION
|
|
104
|
+
* classifyQueryIntent("how does authentication work") // → CONCEPTUAL
|
|
105
|
+
* classifyQueryIntent("how is the API implemented") // → IMPLEMENTATION
|
|
106
|
+
*/
|
|
107
|
+
export function classifyQueryIntent(query) {
|
|
108
|
+
const lower = query.toLowerCase().trim();
|
|
109
|
+
// Use cached sorted rules to avoid re-sorting on every query
|
|
110
|
+
const sortedRules = getSortedRules();
|
|
111
|
+
for (const rule of sortedRules) {
|
|
112
|
+
if (rule.patterns.some(pattern => pattern.test(lower))) {
|
|
113
|
+
return rule.intent;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Default to IMPLEMENTATION for ambiguous queries
|
|
117
|
+
// This is the most common use case for code search
|
|
118
|
+
return QueryIntent.IMPLEMENTATION;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Add a custom intent rule (useful for testing or extensions).
|
|
122
|
+
*
|
|
123
|
+
* Returns a cleanup function that removes the added rule.
|
|
124
|
+
* This prevents test pollution and allows proper cleanup.
|
|
125
|
+
*
|
|
126
|
+
* @param rule - The intent rule to add
|
|
127
|
+
* @returns A cleanup function that removes the added rule
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const cleanup = addIntentRule({
|
|
131
|
+
* intent: QueryIntent.LOCATION,
|
|
132
|
+
* priority: 4,
|
|
133
|
+
* patterns: [/custom pattern/]
|
|
134
|
+
* });
|
|
135
|
+
* // ... use the rule ...
|
|
136
|
+
* cleanup(); // removes the rule
|
|
137
|
+
*/
|
|
138
|
+
export function addIntentRule(rule) {
|
|
139
|
+
INTENT_RULES.push(rule);
|
|
140
|
+
// Invalidate cache since rules have changed
|
|
141
|
+
invalidateSortedRulesCache();
|
|
142
|
+
// Return cleanup function to remove the rule
|
|
143
|
+
return () => {
|
|
144
|
+
const idx = INTENT_RULES.indexOf(rule);
|
|
145
|
+
if (idx !== -1) {
|
|
146
|
+
INTENT_RULES.splice(idx, 1);
|
|
147
|
+
// Invalidate cache since rules have changed
|
|
148
|
+
invalidateSortedRulesCache();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get all patterns for a specific intent (useful for debugging).
|
|
154
|
+
*
|
|
155
|
+
* @param intent - The intent to get patterns for
|
|
156
|
+
* @returns Array of regex patterns for the intent
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* const locationPatterns = getPatternsForIntent(QueryIntent.LOCATION);
|
|
160
|
+
*/
|
|
161
|
+
export function getPatternsForIntent(intent) {
|
|
162
|
+
return INTENT_RULES
|
|
163
|
+
.filter(rule => rule.intent === intent)
|
|
164
|
+
.flatMap(rule => rule.patterns);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get all intent rules (useful for testing/debugging).
|
|
168
|
+
*
|
|
169
|
+
* @returns A copy of the current intent rules
|
|
170
|
+
*/
|
|
171
|
+
export function getIntentRules() {
|
|
172
|
+
return [...INTENT_RULES];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Reset intent rules to initial state.
|
|
176
|
+
*
|
|
177
|
+
* WARNING: This function is intended for testing only.
|
|
178
|
+
* It removes all custom rules added via addIntentRule().
|
|
179
|
+
* The original built-in rules are preserved.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* // In test cleanup
|
|
183
|
+
* afterEach(() => {
|
|
184
|
+
* resetIntentRules();
|
|
185
|
+
* });
|
|
186
|
+
*/
|
|
187
|
+
export function resetIntentRules() {
|
|
188
|
+
// Remove all custom rules, preserving only the original built-in rules
|
|
189
|
+
INTENT_RULES.splice(INITIAL_RULE_COUNT);
|
|
190
|
+
// Invalidate cache since rules have changed
|
|
191
|
+
invalidateSortedRulesCache();
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=intent-classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-classifier.js","sourceRoot":"","sources":["../../src/vectordb/intent-classifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,WASX;AATD,WAAY,WAAW;IACrB,uEAAuE;IACvE,oCAAqB,CAAA;IAErB,4EAA4E;IAC5E,wCAAyB,CAAA;IAEzB,uEAAuE;IACvE,gDAAiC,CAAA;AACnC,CAAC,EATW,WAAW,KAAX,WAAW,QAStB;AAWD;;;GAGG;AACH,MAAM,YAAY,GAAiB;IACjC,qDAAqD;IACrD;QACE,MAAM,EAAE,WAAW,CAAC,QAAQ;QAC5B,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE;YACR,sCAAsC;YACtC,eAAe;YACf,WAAW;SACZ;KACF;IAED,sCAAsC;IACtC;QACE,MAAM,EAAE,WAAW,CAAC,UAAU;QAC9B,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE;YACR,wBAAwB;YACxB,sBAAsB;YACtB,YAAY;YACZ,eAAe;YACf,qCAAqC;SACtC;KACF;IAED,wEAAwE;IACxE;QACE,MAAM,EAAE,WAAW,CAAC,cAAc;QAClC,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE;YACR,iDAAiD;YAC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,EAAE;QACV,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC5B,4CAA4C;YAC5C,0BAA0B,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAmB;IACtD,OAAO,YAAY;SAChB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC;SACtC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB;IAC9B,uEAAuE;IACvE,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAExC,4CAA4C;IAC5C,0BAA0B,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SearchResult, VectorDBInterface } from './types.js';
|
|
2
|
+
import { ChunkMetadata } from '../indexer/types.js';
|
|
3
|
+
export declare class VectorDB implements VectorDBInterface {
|
|
4
|
+
private db;
|
|
5
|
+
private table;
|
|
6
|
+
readonly dbPath: string;
|
|
7
|
+
private readonly tableName;
|
|
8
|
+
private lastVersionCheck;
|
|
9
|
+
private currentVersion;
|
|
10
|
+
constructor(projectRoot: string);
|
|
11
|
+
initialize(): Promise<void>;
|
|
12
|
+
insertBatch(vectors: Float32Array[], metadatas: ChunkMetadata[], contents: string[]): Promise<void>;
|
|
13
|
+
search(queryVector: Float32Array, limit?: number, query?: string): Promise<SearchResult[]>;
|
|
14
|
+
scanWithFilter(options: {
|
|
15
|
+
language?: string;
|
|
16
|
+
pattern?: string;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}): Promise<SearchResult[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Scan all chunks in the database
|
|
21
|
+
* Fetches total count first, then retrieves all chunks in a single optimized query
|
|
22
|
+
* @param options - Filter options (language, pattern)
|
|
23
|
+
* @returns All matching chunks
|
|
24
|
+
*/
|
|
25
|
+
scanAll(options?: {
|
|
26
|
+
language?: string;
|
|
27
|
+
pattern?: string;
|
|
28
|
+
}): Promise<SearchResult[]>;
|
|
29
|
+
querySymbols(options: {
|
|
30
|
+
language?: string;
|
|
31
|
+
pattern?: string;
|
|
32
|
+
symbolType?: 'function' | 'class' | 'interface';
|
|
33
|
+
limit?: number;
|
|
34
|
+
}): Promise<SearchResult[]>;
|
|
35
|
+
clear(): Promise<void>;
|
|
36
|
+
deleteByFile(filepath: string): Promise<void>;
|
|
37
|
+
updateFile(filepath: string, vectors: Float32Array[], metadatas: ChunkMetadata[], contents: string[]): Promise<void>;
|
|
38
|
+
checkVersion(): Promise<boolean>;
|
|
39
|
+
reconnect(): Promise<void>;
|
|
40
|
+
getCurrentVersion(): number;
|
|
41
|
+
getVersionDate(): string;
|
|
42
|
+
hasData(): Promise<boolean>;
|
|
43
|
+
static load(projectRoot: string): Promise<VectorDB>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=lancedb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lancedb.d.ts","sourceRoot":"","sources":["../../src/vectordb/lancedb.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAWpD,qBAAa,QAAS,YAAW,iBAAiB;IAChD,OAAO,CAAC,EAAE,CAAkC;IAC5C,OAAO,CAAC,KAAK,CAA6B;IAC1C,S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