raggrep 0.2.3 → 0.3.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.
- package/dist/app/search/index.d.ts +1 -1
- package/dist/cli/main.js +143 -9
- package/dist/cli/main.js.map +16 -14
- package/dist/domain/entities/searchResult.d.ts +11 -0
- package/dist/index.js +353 -8
- package/dist/index.js.map +14 -12
- package/dist/infrastructure/embeddings/transformersEmbedding.d.ts +1 -1
- package/dist/tests/ranking.test.d.ts +12 -0
- package/package.json +1 -1
package/dist/cli/main.js
CHANGED
|
@@ -12,7 +12,10 @@ var __export = (target, all) => {
|
|
|
12
12
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
13
13
|
|
|
14
14
|
// src/infrastructure/embeddings/transformersEmbedding.ts
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
pipeline,
|
|
17
|
+
env
|
|
18
|
+
} from "@xenova/transformers";
|
|
16
19
|
import * as path from "path";
|
|
17
20
|
import * as os from "os";
|
|
18
21
|
|
|
@@ -169,7 +172,15 @@ var init_embeddings = __esm(() => {
|
|
|
169
172
|
init_transformersEmbedding();
|
|
170
173
|
});
|
|
171
174
|
// src/domain/entities/searchResult.ts
|
|
172
|
-
var
|
|
175
|
+
var DEFAULT_SEARCH_OPTIONS;
|
|
176
|
+
var init_searchResult = __esm(() => {
|
|
177
|
+
DEFAULT_SEARCH_OPTIONS = {
|
|
178
|
+
topK: 10,
|
|
179
|
+
minScore: 0.15,
|
|
180
|
+
filePatterns: [],
|
|
181
|
+
ensureFresh: true
|
|
182
|
+
};
|
|
183
|
+
});
|
|
173
184
|
|
|
174
185
|
// src/domain/entities/config.ts
|
|
175
186
|
function createDefaultConfig() {
|
|
@@ -231,10 +242,17 @@ var init_config = __esm(() => {
|
|
|
231
242
|
".tsx",
|
|
232
243
|
".js",
|
|
233
244
|
".jsx",
|
|
245
|
+
".mjs",
|
|
246
|
+
".cjs",
|
|
234
247
|
".py",
|
|
235
248
|
".go",
|
|
236
249
|
".rs",
|
|
237
250
|
".java",
|
|
251
|
+
".json",
|
|
252
|
+
".yaml",
|
|
253
|
+
".yml",
|
|
254
|
+
".toml",
|
|
255
|
+
".sql",
|
|
238
256
|
".md",
|
|
239
257
|
".txt"
|
|
240
258
|
];
|
|
@@ -2690,6 +2708,57 @@ __export(exports_typescript, {
|
|
|
2690
2708
|
DEFAULT_MIN_SCORE: () => DEFAULT_MIN_SCORE2
|
|
2691
2709
|
});
|
|
2692
2710
|
import * as path8 from "path";
|
|
2711
|
+
function detectQueryIntent(queryTerms) {
|
|
2712
|
+
const hasImplementationTerm = queryTerms.some((term) => IMPLEMENTATION_TERMS.includes(term));
|
|
2713
|
+
const hasDocumentationTerm = queryTerms.some((term) => DOCUMENTATION_TERMS.includes(term));
|
|
2714
|
+
if (hasDocumentationTerm) {
|
|
2715
|
+
return "documentation";
|
|
2716
|
+
}
|
|
2717
|
+
if (hasImplementationTerm) {
|
|
2718
|
+
return "implementation";
|
|
2719
|
+
}
|
|
2720
|
+
return "neutral";
|
|
2721
|
+
}
|
|
2722
|
+
function calculateFileTypeBoost(filepath, queryTerms) {
|
|
2723
|
+
const ext = path8.extname(filepath).toLowerCase();
|
|
2724
|
+
const isSourceCode = SOURCE_CODE_EXTENSIONS.includes(ext);
|
|
2725
|
+
const isDoc = DOC_EXTENSIONS.includes(ext);
|
|
2726
|
+
const intent = detectQueryIntent(queryTerms);
|
|
2727
|
+
if (intent === "implementation") {
|
|
2728
|
+
if (isSourceCode) {
|
|
2729
|
+
return 0.06;
|
|
2730
|
+
}
|
|
2731
|
+
return 0;
|
|
2732
|
+
}
|
|
2733
|
+
if (intent === "documentation") {
|
|
2734
|
+
if (isDoc) {
|
|
2735
|
+
return 0.08;
|
|
2736
|
+
}
|
|
2737
|
+
return 0;
|
|
2738
|
+
}
|
|
2739
|
+
return 0;
|
|
2740
|
+
}
|
|
2741
|
+
function calculateChunkTypeBoost(chunk) {
|
|
2742
|
+
switch (chunk.type) {
|
|
2743
|
+
case "function":
|
|
2744
|
+
return 0.05;
|
|
2745
|
+
case "class":
|
|
2746
|
+
case "interface":
|
|
2747
|
+
return 0.04;
|
|
2748
|
+
case "type":
|
|
2749
|
+
case "enum":
|
|
2750
|
+
return 0.03;
|
|
2751
|
+
case "variable":
|
|
2752
|
+
return 0.02;
|
|
2753
|
+
case "file":
|
|
2754
|
+
case "block":
|
|
2755
|
+
default:
|
|
2756
|
+
return 0;
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
function calculateExportBoost(chunk) {
|
|
2760
|
+
return chunk.isExported ? 0.03 : 0;
|
|
2761
|
+
}
|
|
2693
2762
|
|
|
2694
2763
|
class TypeScriptModule {
|
|
2695
2764
|
id = "language/typescript";
|
|
@@ -2859,7 +2928,11 @@ class TypeScriptModule {
|
|
|
2859
2928
|
const semanticScore = cosineSimilarity(queryEmbedding, embedding);
|
|
2860
2929
|
const bm25Score = bm25Scores.get(chunk.id) || 0;
|
|
2861
2930
|
const pathBoost = pathBoosts.get(filepath) || 0;
|
|
2862
|
-
const
|
|
2931
|
+
const fileTypeBoost = calculateFileTypeBoost(filepath, queryTerms);
|
|
2932
|
+
const chunkTypeBoost = calculateChunkTypeBoost(chunk);
|
|
2933
|
+
const exportBoost = calculateExportBoost(chunk);
|
|
2934
|
+
const totalBoost = pathBoost + fileTypeBoost + chunkTypeBoost + exportBoost;
|
|
2935
|
+
const hybridScore = SEMANTIC_WEIGHT * semanticScore + BM25_WEIGHT * bm25Score + totalBoost;
|
|
2863
2936
|
if (hybridScore >= minScore || bm25Score > 0.3) {
|
|
2864
2937
|
results.push({
|
|
2865
2938
|
filepath,
|
|
@@ -2869,7 +2942,10 @@ class TypeScriptModule {
|
|
|
2869
2942
|
context: {
|
|
2870
2943
|
semanticScore,
|
|
2871
2944
|
bm25Score,
|
|
2872
|
-
pathBoost
|
|
2945
|
+
pathBoost,
|
|
2946
|
+
fileTypeBoost,
|
|
2947
|
+
chunkTypeBoost,
|
|
2948
|
+
exportBoost
|
|
2873
2949
|
}
|
|
2874
2950
|
});
|
|
2875
2951
|
}
|
|
@@ -2901,7 +2977,7 @@ class TypeScriptModule {
|
|
|
2901
2977
|
return references;
|
|
2902
2978
|
}
|
|
2903
2979
|
}
|
|
2904
|
-
var DEFAULT_MIN_SCORE2 = 0.15, DEFAULT_TOP_K2 = 10, SEMANTIC_WEIGHT = 0.7, BM25_WEIGHT = 0.3;
|
|
2980
|
+
var DEFAULT_MIN_SCORE2 = 0.15, DEFAULT_TOP_K2 = 10, SEMANTIC_WEIGHT = 0.7, BM25_WEIGHT = 0.3, IMPLEMENTATION_TERMS, DOCUMENTATION_TERMS, SOURCE_CODE_EXTENSIONS, DOC_EXTENSIONS;
|
|
2905
2981
|
var init_typescript = __esm(() => {
|
|
2906
2982
|
init_embeddings();
|
|
2907
2983
|
init_config2();
|
|
@@ -2909,6 +2985,52 @@ var init_typescript = __esm(() => {
|
|
|
2909
2985
|
init_storage();
|
|
2910
2986
|
init_keywords();
|
|
2911
2987
|
init_keywords();
|
|
2988
|
+
IMPLEMENTATION_TERMS = [
|
|
2989
|
+
"function",
|
|
2990
|
+
"method",
|
|
2991
|
+
"class",
|
|
2992
|
+
"interface",
|
|
2993
|
+
"implement",
|
|
2994
|
+
"implementation",
|
|
2995
|
+
"endpoint",
|
|
2996
|
+
"route",
|
|
2997
|
+
"handler",
|
|
2998
|
+
"controller",
|
|
2999
|
+
"module",
|
|
3000
|
+
"code"
|
|
3001
|
+
];
|
|
3002
|
+
DOCUMENTATION_TERMS = [
|
|
3003
|
+
"documentation",
|
|
3004
|
+
"docs",
|
|
3005
|
+
"guide",
|
|
3006
|
+
"tutorial",
|
|
3007
|
+
"readme",
|
|
3008
|
+
"how",
|
|
3009
|
+
"what",
|
|
3010
|
+
"why",
|
|
3011
|
+
"explain",
|
|
3012
|
+
"overview",
|
|
3013
|
+
"getting",
|
|
3014
|
+
"started",
|
|
3015
|
+
"requirements",
|
|
3016
|
+
"setup",
|
|
3017
|
+
"install",
|
|
3018
|
+
"configure",
|
|
3019
|
+
"configuration"
|
|
3020
|
+
];
|
|
3021
|
+
SOURCE_CODE_EXTENSIONS = [
|
|
3022
|
+
".ts",
|
|
3023
|
+
".tsx",
|
|
3024
|
+
".js",
|
|
3025
|
+
".jsx",
|
|
3026
|
+
".mjs",
|
|
3027
|
+
".cjs",
|
|
3028
|
+
".py",
|
|
3029
|
+
".go",
|
|
3030
|
+
".rs",
|
|
3031
|
+
".java"
|
|
3032
|
+
];
|
|
3033
|
+
DOC_EXTENSIONS = [".md", ".txt", ".rst"];
|
|
2912
3034
|
});
|
|
2913
3035
|
|
|
2914
3036
|
// src/modules/registry.ts
|
|
@@ -3877,6 +3999,11 @@ var init_indexer = __esm(() => {
|
|
|
3877
3999
|
init_watcher();
|
|
3878
4000
|
});
|
|
3879
4001
|
|
|
4002
|
+
// src/types.ts
|
|
4003
|
+
var init_types = __esm(() => {
|
|
4004
|
+
init_entities();
|
|
4005
|
+
});
|
|
4006
|
+
|
|
3880
4007
|
// src/app/search/index.ts
|
|
3881
4008
|
var exports_search = {};
|
|
3882
4009
|
__export(exports_search, {
|
|
@@ -3887,12 +4014,16 @@ import * as fs7 from "fs/promises";
|
|
|
3887
4014
|
import * as path13 from "path";
|
|
3888
4015
|
async function search(rootDir, query, options = {}) {
|
|
3889
4016
|
rootDir = path13.resolve(rootDir);
|
|
4017
|
+
const ensureFresh = options.ensureFresh ?? DEFAULT_SEARCH_OPTIONS.ensureFresh;
|
|
4018
|
+
if (ensureFresh) {
|
|
4019
|
+
await ensureIndexFresh(rootDir, { quiet: true });
|
|
4020
|
+
}
|
|
3890
4021
|
console.log(`Searching for: "${query}"`);
|
|
3891
4022
|
const config = await loadConfig(rootDir);
|
|
3892
4023
|
await registerBuiltInModules();
|
|
3893
4024
|
const globalManifest = await loadGlobalManifest(rootDir, config);
|
|
3894
4025
|
if (!globalManifest || globalManifest.modules.length === 0) {
|
|
3895
|
-
console.log('No index found. Run "
|
|
4026
|
+
console.log('No index found. Run "raggrep index" first.');
|
|
3896
4027
|
return [];
|
|
3897
4028
|
}
|
|
3898
4029
|
const modulesToSearch = [];
|
|
@@ -4015,8 +4146,10 @@ function formatSearchResults(results) {
|
|
|
4015
4146
|
return output;
|
|
4016
4147
|
}
|
|
4017
4148
|
var init_search = __esm(() => {
|
|
4149
|
+
init_types();
|
|
4018
4150
|
init_config2();
|
|
4019
4151
|
init_registry();
|
|
4152
|
+
init_indexer();
|
|
4020
4153
|
});
|
|
4021
4154
|
|
|
4022
4155
|
// src/app/cli/main.ts
|
|
@@ -4024,7 +4157,7 @@ init_embeddings();
|
|
|
4024
4157
|
// package.json
|
|
4025
4158
|
var package_default = {
|
|
4026
4159
|
name: "raggrep",
|
|
4027
|
-
version: "0.
|
|
4160
|
+
version: "0.3.0",
|
|
4028
4161
|
description: "Local filesystem-based RAG system for codebases - semantic search using local embeddings",
|
|
4029
4162
|
type: "module",
|
|
4030
4163
|
main: "./dist/index.js",
|
|
@@ -4314,7 +4447,8 @@ Examples:
|
|
|
4314
4447
|
const results = await search2(process.cwd(), query, {
|
|
4315
4448
|
topK: flags.topK ?? 10,
|
|
4316
4449
|
minScore: flags.minScore,
|
|
4317
|
-
filePatterns
|
|
4450
|
+
filePatterns,
|
|
4451
|
+
ensureFresh: false
|
|
4318
4452
|
});
|
|
4319
4453
|
console.log(formatSearchResults2(results));
|
|
4320
4454
|
} catch (error) {
|
|
@@ -4461,4 +4595,4 @@ Run 'raggrep <command> --help' for more information.
|
|
|
4461
4595
|
}
|
|
4462
4596
|
main();
|
|
4463
4597
|
|
|
4464
|
-
//# debugId=
|
|
4598
|
+
//# debugId=F7638DADE034B49B64756E2164756E21
|