@tobilu/qmd 1.1.1 → 1.1.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/CHANGELOG.md +82 -0
- package/README.md +29 -3
- package/dist/collections.d.ts +1 -0
- package/dist/formatter.d.ts +1 -0
- package/dist/formatter.js +4 -4
- package/dist/llm.d.ts +20 -5
- package/dist/llm.js +102 -51
- package/dist/mcp.js +86 -10
- package/dist/qmd.js +145 -60
- package/dist/store.d.ts +62 -15
- package/dist/store.js +224 -33
- package/package.json +4 -3
package/dist/store.d.ts
CHANGED
|
@@ -202,11 +202,11 @@ export type Store = {
|
|
|
202
202
|
toVirtualPath: (absolutePath: string) => string | null;
|
|
203
203
|
searchFTS: (query: string, limit?: number, collectionName?: string) => SearchResult[];
|
|
204
204
|
searchVec: (query: string, model: string, limit?: number, collectionName?: string, session?: ILLMSession, precomputedEmbedding?: number[]) => Promise<SearchResult[]>;
|
|
205
|
-
expandQuery: (query: string, model?: string) => Promise<ExpandedQuery[]>;
|
|
205
|
+
expandQuery: (query: string, model?: string, intent?: string) => Promise<ExpandedQuery[]>;
|
|
206
206
|
rerank: (query: string, documents: {
|
|
207
207
|
file: string;
|
|
208
208
|
text: string;
|
|
209
|
-
}[], model?: string) => Promise<{
|
|
209
|
+
}[], model?: string, intent?: string) => Promise<{
|
|
210
210
|
file: string;
|
|
211
211
|
score: number;
|
|
212
212
|
}[]>;
|
|
@@ -280,15 +280,6 @@ export type DocumentResult = {
|
|
|
280
280
|
* Extract short docid from a full hash (first 6 characters).
|
|
281
281
|
*/
|
|
282
282
|
export declare function getDocid(hash: string): string;
|
|
283
|
-
/**
|
|
284
|
-
* Handelize a filename to be more token-friendly.
|
|
285
|
-
* - Convert triple underscore `___` to `/` (folder separator)
|
|
286
|
-
* - Convert to lowercase
|
|
287
|
-
* - Replace sequences of non-word chars (except /) with single dash
|
|
288
|
-
* - Remove leading/trailing dashes from path segments
|
|
289
|
-
* - Preserve folder structure (a/b/c/d.md stays structured)
|
|
290
|
-
* - Preserve file extension
|
|
291
|
-
*/
|
|
292
283
|
export declare function handelize(path: string): string;
|
|
293
284
|
/**
|
|
294
285
|
* Search result extends DocumentResult with score and source info
|
|
@@ -308,6 +299,38 @@ export type RankedResult = {
|
|
|
308
299
|
body: string;
|
|
309
300
|
score: number;
|
|
310
301
|
};
|
|
302
|
+
export type RRFContributionTrace = {
|
|
303
|
+
listIndex: number;
|
|
304
|
+
source: "fts" | "vec";
|
|
305
|
+
queryType: "original" | "lex" | "vec" | "hyde";
|
|
306
|
+
query: string;
|
|
307
|
+
rank: number;
|
|
308
|
+
weight: number;
|
|
309
|
+
backendScore: number;
|
|
310
|
+
rrfContribution: number;
|
|
311
|
+
};
|
|
312
|
+
export type RRFScoreTrace = {
|
|
313
|
+
contributions: RRFContributionTrace[];
|
|
314
|
+
baseScore: number;
|
|
315
|
+
topRank: number;
|
|
316
|
+
topRankBonus: number;
|
|
317
|
+
totalScore: number;
|
|
318
|
+
};
|
|
319
|
+
export type HybridQueryExplain = {
|
|
320
|
+
ftsScores: number[];
|
|
321
|
+
vectorScores: number[];
|
|
322
|
+
rrf: {
|
|
323
|
+
rank: number;
|
|
324
|
+
positionScore: number;
|
|
325
|
+
weight: number;
|
|
326
|
+
baseScore: number;
|
|
327
|
+
topRankBonus: number;
|
|
328
|
+
totalScore: number;
|
|
329
|
+
contributions: RRFContributionTrace[];
|
|
330
|
+
};
|
|
331
|
+
rerankScore: number;
|
|
332
|
+
blendedScore: number;
|
|
333
|
+
};
|
|
311
334
|
/**
|
|
312
335
|
* Error result when document is not found
|
|
313
336
|
*/
|
|
@@ -575,15 +598,19 @@ export declare function clearAllEmbeddings(db: Database): void;
|
|
|
575
598
|
* The hash_seq key is formatted as "hash_seq" for the vectors_vec table.
|
|
576
599
|
*/
|
|
577
600
|
export declare function insertEmbedding(db: Database, hash: string, seq: number, pos: number, embedding: Float32Array, model: string, embeddedAt: string): void;
|
|
578
|
-
export declare function expandQuery(query: string, model: string | undefined, db: Database): Promise<ExpandedQuery[]>;
|
|
601
|
+
export declare function expandQuery(query: string, model: string | undefined, db: Database, intent?: string): Promise<ExpandedQuery[]>;
|
|
579
602
|
export declare function rerank(query: string, documents: {
|
|
580
603
|
file: string;
|
|
581
604
|
text: string;
|
|
582
|
-
}[], model: string | undefined, db: Database): Promise<{
|
|
605
|
+
}[], model: string | undefined, db: Database, intent?: string): Promise<{
|
|
583
606
|
file: string;
|
|
584
607
|
score: number;
|
|
585
608
|
}[]>;
|
|
586
609
|
export declare function reciprocalRankFusion(resultLists: RankedResult[][], weights?: number[], k?: number): RankedResult[];
|
|
610
|
+
/**
|
|
611
|
+
* Build per-document RRF contribution traces for explain/debug output.
|
|
612
|
+
*/
|
|
613
|
+
export declare function buildRrfTrace(resultLists: RankedResult[][], weights?: number[], listMeta?: RankedListMeta[], k?: number): Map<string, RRFScoreTrace>;
|
|
587
614
|
/**
|
|
588
615
|
* Find a document by filename/path, docid (#hash), or with fuzzy matching.
|
|
589
616
|
* Returns document metadata without body by default.
|
|
@@ -623,7 +650,17 @@ export type SnippetResult = {
|
|
|
623
650
|
linesAfter: number;
|
|
624
651
|
snippetLines: number;
|
|
625
652
|
};
|
|
626
|
-
|
|
653
|
+
/** Weight for intent terms relative to query terms (1.0) in snippet scoring */
|
|
654
|
+
export declare const INTENT_WEIGHT_SNIPPET = 0.3;
|
|
655
|
+
/** Weight for intent terms relative to query terms (1.0) in chunk selection */
|
|
656
|
+
export declare const INTENT_WEIGHT_CHUNK = 0.5;
|
|
657
|
+
/**
|
|
658
|
+
* Extract meaningful terms from an intent string, filtering stop words and punctuation.
|
|
659
|
+
* Uses Unicode-aware punctuation stripping so domain terms like "API" survive.
|
|
660
|
+
* Returns lowercase terms suitable for text matching.
|
|
661
|
+
*/
|
|
662
|
+
export declare function extractIntentTerms(intent: string): string[];
|
|
663
|
+
export declare function extractSnippet(body: string, query: string, maxLen?: number, chunkPos?: number, chunkLen?: number, intent?: string): SnippetResult;
|
|
627
664
|
/**
|
|
628
665
|
* Add line numbers to text content.
|
|
629
666
|
* Each line becomes: "{lineNum}: {content}"
|
|
@@ -654,6 +691,8 @@ export interface HybridQueryOptions {
|
|
|
654
691
|
limit?: number;
|
|
655
692
|
minScore?: number;
|
|
656
693
|
candidateLimit?: number;
|
|
694
|
+
explain?: boolean;
|
|
695
|
+
intent?: string;
|
|
657
696
|
hooks?: SearchHooks;
|
|
658
697
|
}
|
|
659
698
|
export interface HybridQueryResult {
|
|
@@ -666,7 +705,13 @@ export interface HybridQueryResult {
|
|
|
666
705
|
score: number;
|
|
667
706
|
context: string | null;
|
|
668
707
|
docid: string;
|
|
708
|
+
explain?: HybridQueryExplain;
|
|
669
709
|
}
|
|
710
|
+
export type RankedListMeta = {
|
|
711
|
+
source: "fts" | "vec";
|
|
712
|
+
queryType: "original" | "lex" | "vec" | "hyde";
|
|
713
|
+
query: string;
|
|
714
|
+
};
|
|
670
715
|
/**
|
|
671
716
|
* Hybrid search: BM25 + vector + query expansion + RRF + chunked reranking.
|
|
672
717
|
*
|
|
@@ -685,6 +730,7 @@ export interface VectorSearchOptions {
|
|
|
685
730
|
collection?: string;
|
|
686
731
|
limit?: number;
|
|
687
732
|
minScore?: number;
|
|
733
|
+
intent?: string;
|
|
688
734
|
hooks?: Pick<SearchHooks, 'onExpand'>;
|
|
689
735
|
}
|
|
690
736
|
export interface VectorSearchResult {
|
|
@@ -723,7 +769,8 @@ export interface StructuredSearchOptions {
|
|
|
723
769
|
limit?: number;
|
|
724
770
|
minScore?: number;
|
|
725
771
|
candidateLimit?: number;
|
|
726
|
-
|
|
772
|
+
explain?: boolean;
|
|
773
|
+
/** Domain intent hint for disambiguation — steers reranking and chunk selection */
|
|
727
774
|
intent?: string;
|
|
728
775
|
hooks?: SearchHooks;
|
|
729
776
|
}
|