@autorag/librarian 2.8.0 → 2.10.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.
Files changed (97) hide show
  1. package/NOTICE +4 -4
  2. package/README.md +120 -24
  3. package/dist/agent/agent.d.ts +147 -78
  4. package/dist/agent/answer-citations.d.ts +22 -0
  5. package/dist/agent/answer-guidelines.d.ts +9 -9
  6. package/dist/agent/citations.d.ts +42 -7
  7. package/dist/agent/datasource-skill.d.ts +30 -16
  8. package/dist/agent/evidence-judgment.d.ts +58 -0
  9. package/dist/agent/evidence-ledger.d.ts +54 -0
  10. package/dist/agent/evidence-origins.d.ts +49 -0
  11. package/dist/agent/index.d.ts +2 -2
  12. package/dist/agent/jikji-find-tool.d.ts +2 -1
  13. package/dist/agent/pi-session.d.ts +8 -1
  14. package/dist/agent/query-peer-tool.d.ts +3 -0
  15. package/dist/agent/query-routing.d.ts +71 -10
  16. package/dist/agent/{emit-results-tool.d.ts → results.d.ts} +11 -11
  17. package/dist/agent/search-all-tool.d.ts +5 -5
  18. package/dist/agent/search-documents.d.ts +14 -27
  19. package/dist/agent/search-minsync-tool.d.ts +5 -5
  20. package/dist/agent/search-single-datasource-tool.d.ts +9 -8
  21. package/dist/agent/self-config.d.ts +40 -0
  22. package/dist/agent/system-prompt.d.ts +2 -3
  23. package/dist/agent/web-fetch-tool.d.ts +2 -1
  24. package/dist/agent/web-search-tool.d.ts +2 -1
  25. package/dist/cli/commands/evidence.d.ts +2 -2
  26. package/dist/cli/commands/memory.d.ts +1 -1
  27. package/dist/cli/commands/report.d.ts +2 -2
  28. package/dist/cli/commands/tui.d.ts +3 -2
  29. package/dist/cli/config.d.ts +16 -8
  30. package/dist/cli/index.d.ts +1 -1
  31. package/dist/cli/index.js +11133 -10103
  32. package/dist/cli/output.d.ts +2 -6
  33. package/dist/cloud/authorize.d.ts +12 -0
  34. package/dist/cloud/callback-server.d.ts +33 -0
  35. package/dist/cloud/callback.d.ts +23 -0
  36. package/dist/cloud/config.d.ts +23 -0
  37. package/dist/cloud/errors.d.ts +46 -0
  38. package/dist/cloud/index.d.ts +12 -0
  39. package/dist/cloud/models.d.ts +32 -0
  40. package/dist/cloud/oauth-login.d.ts +22 -0
  41. package/dist/cloud/pkce.d.ts +20 -0
  42. package/dist/cloud/provider.d.ts +40 -0
  43. package/dist/cloud/token.d.ts +22 -0
  44. package/dist/config/home.d.ts +6 -0
  45. package/dist/core.d.ts +10 -21
  46. package/dist/core.js +15272 -14207
  47. package/dist/datasource/chunk-store.d.ts +2 -6
  48. package/dist/datasource/connector-skill.d.ts +2 -3
  49. package/dist/datasource/index.d.ts +2 -4
  50. package/dist/datasource/registry.d.ts +11 -13
  51. package/dist/datasource/scope.d.ts +19 -0
  52. package/dist/datasource/skills/github-gist/index.d.ts +1 -1
  53. package/dist/datasource/skills/github-gist/semantic.d.ts +3 -44
  54. package/dist/datasource/skills/github-gist/skill.d.ts +3 -3
  55. package/dist/datasource/types.d.ts +14 -28
  56. package/dist/embedding-runtime/gateway-embedder.d.ts +41 -0
  57. package/dist/index.d.ts +2 -1
  58. package/dist/index.js +15488 -14359
  59. package/dist/language.d.ts +2 -1
  60. package/dist/mcp/index.js +15413 -14341
  61. package/dist/memory/check-memory-tool.d.ts +8 -4
  62. package/dist/memory/context.d.ts +51 -0
  63. package/dist/memory/index.d.ts +8 -1
  64. package/dist/memory/judged-evidence.d.ts +32 -0
  65. package/dist/memory/memory.d.ts +36 -120
  66. package/dist/memory/renderer.d.ts +16 -7
  67. package/dist/memory/similar-queries.d.ts +40 -0
  68. package/dist/minsync/client.d.ts +1 -1
  69. package/dist/minsync/errors.d.ts +14 -0
  70. package/dist/minsync/index.d.ts +1 -0
  71. package/dist/minsync/installer.d.ts +1 -1
  72. package/dist/minsync/method.d.ts +3 -3
  73. package/dist/mirror/sync.d.ts +5 -2
  74. package/dist/observability/run-log.d.ts +1 -1
  75. package/dist/parser/defaults.d.ts +16 -5
  76. package/dist/parser/index.d.ts +1 -1
  77. package/dist/parser/kordoc.d.ts +8 -1
  78. package/dist/parser/ocr-engines.d.ts +19 -0
  79. package/dist/retrieval/bm25.d.ts +19 -0
  80. package/dist/retrieval/engine.d.ts +17 -58
  81. package/dist/retrieval/index.d.ts +3 -2
  82. package/dist/retrieval/merger.d.ts +6 -0
  83. package/dist/retrieval/rerank.d.ts +2 -2
  84. package/dist/retrieval/selection.d.ts +33 -41
  85. package/dist/retrieval/types.d.ts +1 -26
  86. package/dist/web/search/format.d.ts +5 -2
  87. package/dist/web/search/index.d.ts +7 -1
  88. package/package.json +5 -5
  89. package/skills/autorag/SKILL.md +21 -22
  90. package/skills/autorag-doctor/SKILL.md +20 -15
  91. package/skills/autorag-lite-setup/SKILL.md +22 -19
  92. package/skills/autorag-setup/SKILL.md +34 -21
  93. package/dist/agent/fast-answer-tool.d.ts +0 -46
  94. package/dist/cli/commands/feedback.d.ts +0 -8
  95. package/dist/datasource/access-context.d.ts +0 -43
  96. package/dist/datasource/result-filter.d.ts +0 -64
  97. package/dist/parser/ocr.d.ts +0 -31
@@ -1,14 +1,18 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { Type } from "typebox";
3
+ import { type MemoryContextOptions } from "./context.js";
3
4
  import type { RetrievalMemory } from "./memory.js";
4
5
  declare const checkMemorySchema: Type.TObject<{
5
6
  query: Type.TString;
6
7
  }>;
7
8
  export interface CheckMemoryDetails {
8
- signalCount: number;
9
- topMethod: string | null;
9
+ currentCount: number;
10
+ similarCount: number;
10
11
  insightCount: number;
11
- contextHintCount: number;
12
12
  }
13
- export declare function createCheckMemoryTool(memory: RetrievalMemory): AgentTool<typeof checkMemorySchema, CheckMemoryDetails>;
13
+ /**
14
+ * `options` returns undefined when this session must not read retrieval memory
15
+ * (remote P2P peers); the tool then answers as if memory were empty.
16
+ */
17
+ export declare function createCheckMemoryTool(memory: RetrievalMemory, options: () => MemoryContextOptions | undefined): AgentTool<typeof checkMemorySchema, CheckMemoryDetails>;
14
18
  export {};
@@ -0,0 +1,51 @@
1
+ import type { Embedder } from "../embedding-runtime/gateway-embedder.js";
2
+ import type { JudgedEvidenceRecord } from "./judged-evidence.js";
3
+ import type { RetrievalInsight, RetrievalMemory } from "./memory.js";
4
+ import { type SimilarQuestion } from "./similar-queries.js";
5
+ export interface MemoryContextOptions {
6
+ readonly conversationId: string;
7
+ /**
8
+ * Per-record gate applied to both the current conversation's evidence and
9
+ * the past evidence considered for similarity. Memory is shared across
10
+ * workspaces, so the agent uses this to drop evidence from datasources that
11
+ * are not configured for the current run.
12
+ */
13
+ readonly isVisible?: (record: JudgedEvidenceRecord) => boolean;
14
+ /**
15
+ * Per-insight gate applied to the matching long-term insights. Insights name
16
+ * sources and methods, so the same datasource-scope filter drops the ones
17
+ * whose sources the current run cannot read.
18
+ */
19
+ readonly isInsightVisible?: (insight: RetrievalInsight) => boolean;
20
+ readonly embedder?: Embedder;
21
+ readonly vectorStorePath?: string;
22
+ }
23
+ export interface MemoryContext {
24
+ /** The advisory markdown the librarian agent receives. */
25
+ readonly text: string;
26
+ /** True when there is nothing to show. */
27
+ readonly empty: boolean;
28
+ /** Current-conversation evidence after {@link MemoryContextOptions.isVisible}, before the render cap; reusable by the caller. */
29
+ readonly current: readonly JudgedEvidenceRecord[];
30
+ /**
31
+ * The same similarity search kept unfiltered, including questions from the
32
+ * current conversation. The agent uses it to hint at datasources, so a
33
+ * follow-up in the same session still finds the earlier question.
34
+ */
35
+ readonly related: readonly SimilarQuestion[];
36
+ /** Similar questions from other conversations only (current-conversation records removed); what is rendered. */
37
+ readonly similar: readonly SimilarQuestion[];
38
+ /** Records rendered from the current conversation (capped at {@link CURRENT_CONVERSATION_RECORD_LIMIT}). */
39
+ readonly currentCount: number;
40
+ /** Similar past questions found. */
41
+ readonly similarCount: number;
42
+ readonly insightCount: number;
43
+ /** Why semantic matching was skipped, verbatim from {@link findSimilarQuestions}. */
44
+ readonly fallbackReason?: string;
45
+ }
46
+ /**
47
+ * Gathers this conversation's judged evidence, similar past questions, and
48
+ * matching long-term insights into one advisory context. Never throws:
49
+ * {@link findSimilarQuestions} degrades to keywords and reports why.
50
+ */
51
+ export declare function loadMemoryContext(memory: RetrievalMemory, query: string, options: MemoryContextOptions): Promise<MemoryContext>;
@@ -1,5 +1,12 @@
1
1
  export type { CheckMemoryDetails } from "./check-memory-tool.js";
2
2
  export { createCheckMemoryTool } from "./check-memory-tool.js";
3
- export type { ContextValueHint, EvidenceContext, FeedbackIdInput, MemoryEntry, ResultFeedback, RetrievalContextHints, RetrievalInsight, RetrievalMemoryOptions, SearchAttempt, } from "./memory.js";
3
+ export type { MemoryContext, MemoryContextOptions } from "./context.js";
4
+ export { loadMemoryContext } from "./context.js";
5
+ export type { JudgedEvidenceRecord } from "./judged-evidence.js";
6
+ export { EVIDENCE_SUPPORT_THRESHOLD } from "./judged-evidence.js";
7
+ export type { CuratedResultRecord, EvidenceChunkRecord, EvidenceContext, InsightExtractor, MemorySchema, RetrievalInsight, RetrievalMemoryOptions, SessionEvidenceRef, } from "./memory.js";
4
8
  export { normalizeSessionEvidenceRef, RetrievalMemory } from "./memory.js";
9
+ export type { MemoryContextSections } from "./renderer.js";
5
10
  export { renderMemoryContext } from "./renderer.js";
11
+ export type { SimilarQuestion } from "./similar-queries.js";
12
+ export { findSimilarQuestions, SIMILAR_QUESTION_LIMIT } from "./similar-queries.js";
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Evidence the final answer cited and Jev judged to support the user's
3
+ * question. This is the unit retrieval memory stores: a question, the search
4
+ * query and method that surfaced the evidence, and the evidence itself.
5
+ */
6
+ export interface JudgedEvidenceRecord {
7
+ /** `<sessionId>:<stableEvidenceId>`; unique per search run and evidence. */
8
+ readonly id: string;
9
+ /** The search run (one `searchDocuments` call) that produced the evidence. */
10
+ readonly sessionId: string;
11
+ /** The agent conversation the run belonged to; "current session" memory is keyed on it. */
12
+ readonly conversationId: string;
13
+ /** The user's original question. */
14
+ readonly question: string;
15
+ /** The search query that surfaced the evidence (the question itself when no sub-query is known). */
16
+ readonly searchQuery: string;
17
+ /** Retrieval method or tool that surfaced the evidence. */
18
+ readonly method: string;
19
+ /** Opaque source identifier of the evidence. */
20
+ readonly source: string;
21
+ readonly stableEvidenceId: string;
22
+ /** Number and title of the curated result the evidence backs. */
23
+ readonly resultNumber: number;
24
+ readonly title: string;
25
+ /** Bounded evidence text. */
26
+ readonly excerpt: string;
27
+ /** Jev's P(this evidence supports the question), at or above {@link EVIDENCE_SUPPORT_THRESHOLD}. */
28
+ readonly probability: number;
29
+ readonly createdAt: number;
30
+ }
31
+ /** Evidence is kept in memory only when Jev's P(supports the question) reaches this. */
32
+ export declare const EVIDENCE_SUPPORT_THRESHOLD = 0.7;
@@ -1,13 +1,5 @@
1
1
  import { type NormalizedEvidenceRef } from "../retrieval/evidence-id.js";
2
- export type FeedbackOutcome = "pending" | "useful" | "not_useful";
3
- export type FeedbackSentiment = "useful" | "not_useful";
4
- export type FeedbackSignalSource = "explicit" | "followup" | "retry";
5
- export interface SignalDefaults {
6
- readonly explicitWeight: number;
7
- readonly followupWeight: number;
8
- readonly retryWeight: number;
9
- readonly implicitCap: number;
10
- }
2
+ import type { JudgedEvidenceRecord } from "./judged-evidence.js";
11
3
  export interface EvidenceContext {
12
4
  readonly retrieverMix?: readonly string[];
13
5
  readonly parserType?: string;
@@ -35,46 +27,7 @@ export interface CuratedResultRecord {
35
27
  readonly confidence?: number;
36
28
  readonly createdAt: number;
37
29
  }
38
- export interface FeedbackSignal {
39
- readonly id: string;
40
- readonly target: {
41
- readonly type: "curated_result";
42
- readonly resultId: string;
43
- } | {
44
- readonly type: "evidence_chunk";
45
- readonly stableEvidenceId: string;
46
- } | {
47
- readonly type: "method";
48
- readonly method: string;
49
- };
50
- readonly query: string;
51
- readonly method?: string;
52
- readonly sentiment: FeedbackSentiment;
53
- readonly source: FeedbackSignalSource;
54
- readonly weight: number;
55
- readonly confidenceCap: number;
56
- readonly eventId: string;
57
- readonly timestamp: number;
58
- }
59
- export interface MethodHint {
60
- readonly method: string;
61
- readonly score: number;
62
- readonly confidence: number;
63
- readonly reason: string;
64
- }
65
- export interface ContextValueHint {
66
- readonly value: string;
67
- readonly score: number;
68
- readonly confidence: number;
69
- }
70
- export interface RetrievalContextHints {
71
- readonly documentAreas: readonly ContextValueHint[];
72
- readonly documentTypes: readonly ContextValueHint[];
73
- readonly evidenceTypes: readonly ContextValueHint[];
74
- readonly evidenceLocations: readonly ContextValueHint[];
75
- readonly parserTypes: readonly ContextValueHint[];
76
- readonly retrieverMix: readonly ContextValueHint[];
77
- }
30
+ /** A long-term lesson summarized from a batch of judged evidence about one kind of question. */
78
31
  export interface RetrievalInsight {
79
32
  readonly id: string;
80
33
  readonly clusterKey: string;
@@ -82,52 +35,32 @@ export interface RetrievalInsight {
82
35
  readonly recommendedSources: string[];
83
36
  readonly recommendedMethods: string[];
84
37
  readonly rationale: string;
85
- supportingSignalCount: number;
38
+ supportingEvidenceCount: number;
86
39
  confidence: number;
87
40
  readonly createdAt: number;
88
41
  updatedAt: number;
89
42
  }
90
- export interface InsightExtractionSignal {
91
- readonly signal: FeedbackSignal;
92
- readonly method?: string;
93
- readonly source?: string;
94
- }
95
- export type InsightExtractor = (signals: readonly InsightExtractionSignal[], now: number) => RetrievalInsight[];
43
+ /** Summarizes one batch of judged evidence into insights. */
44
+ export type InsightExtractor = (records: readonly JudgedEvidenceRecord[], now: number) => RetrievalInsight[];
96
45
  export interface MemoryWarning {
97
46
  readonly code: string;
98
47
  readonly message: string;
99
48
  readonly timestamp: number;
100
49
  }
101
- export interface MemorySchemaV4 {
102
- readonly version: 4;
50
+ export interface MemorySchema {
51
+ readonly version: 5;
103
52
  curatedResults: CuratedResultRecord[];
104
53
  evidenceChunks: EvidenceChunkRecord[];
105
- feedbackSignals: FeedbackSignal[];
106
- readonly signalDefaults: SignalDefaults;
54
+ /** Every piece of evidence Jev judged to support the question it was cited for. Never evicted. */
55
+ judgedEvidence: JudgedEvidenceRecord[];
107
56
  warnings: MemoryWarning[];
108
57
  insights: RetrievalInsight[];
109
- pendingInsightSignals: InsightExtractionSignal[];
110
- }
111
- export interface MemoryEntry {
112
- id: string;
113
- query: string;
114
- method: string;
115
- outcome: FeedbackOutcome;
116
- timestamp: number;
117
- metadata?: {
118
- resultCount?: number;
119
- };
120
- }
121
- export interface SearchAttempt {
122
- id: string;
123
- query: string;
124
- method: string;
125
- sources: string[];
126
- timestamp: number;
58
+ /** Ids of judged evidence not yet summarized into insights; summarized 100 at a time. */
59
+ pendingInsightEntries: string[];
127
60
  }
128
- export interface ResultFeedback {
129
- source: string;
130
- useful: boolean;
61
+ export interface RetrievalMemoryOptions {
62
+ storagePath: string;
63
+ insightExtractor?: InsightExtractor;
131
64
  }
132
65
  export interface SessionEvidenceRef extends NormalizedEvidenceRef, EvidenceContext {
133
66
  readonly metadata?: Record<string, unknown>;
@@ -147,61 +80,44 @@ export interface SessionRecordInput {
147
80
  readonly query: string;
148
81
  readonly results: readonly SessionCuratedResultInput[];
149
82
  }
150
- export interface NumberedFeedbackInput {
151
- readonly sessionId: string;
152
- readonly query: string;
153
- readonly feedback: readonly {
154
- readonly number: number;
155
- readonly useful: boolean;
156
- }[];
157
- }
158
- export interface FeedbackIdInput {
159
- readonly feedbackId: string;
160
- readonly useful: boolean;
161
- }
162
- export interface RetrievalMemoryOptions {
163
- storagePath: string;
164
- insightExtractor?: InsightExtractor;
165
- }
83
+ /**
84
+ * Long-term retrieval memory: the evidence Jev judged to genuinely support the
85
+ * question it was cited for, plus the curated results and evidence chunks of
86
+ * past searches. Nothing is evicted; every 100 judged records are summarized
87
+ * into long-term insights.
88
+ */
166
89
  export declare class RetrievalMemory {
167
90
  private readonly storagePath;
168
91
  private readonly insightExtractor;
169
92
  private data;
170
93
  private persistedData;
171
- private legacyEntries;
172
- private legacySourceToAttemptId;
173
94
  constructor(options: RetrievalMemoryOptions);
174
95
  load(): void;
175
96
  save(): void;
176
- getSchema(): MemorySchemaV4;
177
- getSignalCount(): number;
97
+ getSchema(): MemorySchema;
98
+ getJudgedEvidence(): readonly JudgedEvidenceRecord[];
99
+ /** Everything judged during one conversation, oldest first. */
100
+ getConversationEvidence(conversationId: string): JudgedEvidenceRecord[];
178
101
  recordCuratedResultsSession(input: SessionRecordInput): void;
179
- recordNumberedFeedback(input: NumberedFeedbackInput): boolean;
180
- recordFeedbackByIds(feedback: readonly FeedbackIdInput[]): boolean;
181
- recordWeakSignal(query: string, method: string, source: "followup" | "retry"): void;
182
- getMethodHints(_query: string): MethodHint[];
183
- getContextHints(_query: string): RetrievalContextHints;
102
+ /** Remember judged evidence. A record already stored under the same id is left as it was. */
103
+ recordJudgedEvidence(records: readonly JudgedEvidenceRecord[]): void;
184
104
  getInsights(query: string): RetrievalInsight[];
185
- getMethodPriority(query: string): Array<{
186
- method: string;
187
- score: number;
188
- }>;
189
- append(entry: Omit<MemoryEntry, "id" | "timestamp">): MemoryEntry;
190
- getEntries(): readonly MemoryEntry[];
191
- registerAttempt(attempt: SearchAttempt): void;
192
- recordResultFeedback(feedback: ResultFeedback[]): void;
193
- resolvePendingEntries(query: string, method: string | null, outcome: "useful" | "not_useful"): void;
194
- recordFeedback(query: string, methodName: string, satisfied: boolean): void;
195
105
  private readPersistedData;
196
106
  private incompatibleMemory;
197
107
  private acquireLock;
108
+ /**
109
+ * Fold what this instance added since it last loaded or saved into the file
110
+ * as it is now, so processes saving independently never overwrite each other.
111
+ */
198
112
  private mergeWithPersisted;
199
- private capData;
200
- private extractInsightsFromEvictedSignals;
113
+ /**
114
+ * Every full group of 100 pending judged records is summarized into
115
+ * insights; the remainder waits for the next batch. A failing extractor never
116
+ * blocks the save, and the batch it failed on is not retried.
117
+ */
118
+ private summarizeCompleteBatches;
201
119
  private mergeInsights;
202
120
  private upsertEvidence;
203
- private methodForSignal;
204
- private sourceForSignal;
205
121
  }
206
122
  export declare function normalizeSessionEvidenceRef(input: Omit<SessionEvidenceRef, "stableEvidenceId"> & {
207
123
  readonly stableEvidenceId?: string;
@@ -1,7 +1,16 @@
1
- import type { MethodHint, RetrievalContextHints, RetrievalInsight } from "./memory.js";
2
- export declare function renderMemoryContext(hints: readonly MethodHint[], opts?: {
3
- maxHints?: number;
4
- insights?: readonly RetrievalInsight[];
5
- maxInsights?: number;
6
- contextHints?: RetrievalContextHints;
7
- }): string;
1
+ import type { JudgedEvidenceRecord } from "./judged-evidence.js";
2
+ import type { RetrievalInsight } from "./memory.js";
3
+ import type { SimilarQuestion } from "./similar-queries.js";
4
+ /** Most recent judged records shown verbatim from one conversation; older ones are summarized. */
5
+ export declare const CURRENT_CONVERSATION_RECORD_LIMIT = 50;
6
+ export interface MemoryContextSections {
7
+ readonly current: readonly JudgedEvidenceRecord[];
8
+ readonly similar: readonly SimilarQuestion[];
9
+ readonly insights: readonly RetrievalInsight[];
10
+ }
11
+ /**
12
+ * Renders retrieval memory as advisory markdown for the librarian agent. Empty
13
+ * sections are omitted. Questions and evidence are JSON-quoted; insight table
14
+ * cells escape backslashes, pipes, and newlines to preserve the table structure.
15
+ */
16
+ export declare function renderMemoryContext(sections: MemoryContextSections): string;
@@ -0,0 +1,40 @@
1
+ import type { Embedder } from "../embedding-runtime/gateway-embedder.js";
2
+ import type { JudgedEvidenceRecord } from "./judged-evidence.js";
3
+ /** How many similar past questions memory brings back for one question. */
4
+ export declare const SIMILAR_QUESTION_LIMIT = 25;
5
+ /**
6
+ * Cosine similarity below this is not a semantic match. Embedding models give
7
+ * unrelated short texts a clearly positive cosine, so a bare "top N by
8
+ * cosine" would always return something.
9
+ */
10
+ export declare const VECTOR_MIN_SIMILARITY = 0.5;
11
+ /** A past question and the evidence Jev kept for it, best evidence first. */
12
+ export interface SimilarQuestion {
13
+ readonly question: string;
14
+ /** Fused BM25 + vector rank score; only meaningful for ordering. */
15
+ readonly score: number;
16
+ readonly records: readonly JudgedEvidenceRecord[];
17
+ }
18
+ export interface SimilarQuestionsOptions {
19
+ readonly limit?: number;
20
+ /** Adds semantic matching; without it only BM25 ranks. */
21
+ readonly embedder?: Embedder;
22
+ /** Where question vectors are cached; unset keeps them in memory for this call only. */
23
+ readonly vectorStorePath?: string;
24
+ }
25
+ export interface SimilarQuestionsResult {
26
+ readonly questions: readonly SimilarQuestion[];
27
+ /** Why semantic matching was skipped (verbatim error); absent when it ran or no embedder was given. */
28
+ readonly fallbackReason?: string;
29
+ }
30
+ /** The vector cache lives beside the memory file it indexes. */
31
+ export declare function memoryVectorStorePath(memoryPath: string): string;
32
+ /**
33
+ * Past questions that resemble `query`, with the evidence Jev judged to
34
+ * support each. Keyword (BM25) and semantic (vector) rankings are fused by
35
+ * reciprocal rank, so a question found by both outranks one found by either
36
+ * alone, and a rephrasing that shares no word with the query is still found
37
+ * semantically. Never throws: a failed embedder degrades to keywords only and
38
+ * says why.
39
+ */
40
+ export declare function findSimilarQuestions(records: readonly JudgedEvidenceRecord[], query: string, options?: SimilarQuestionsOptions): Promise<SimilarQuestionsResult>;
@@ -14,7 +14,7 @@ export interface MinSyncClientOptions {
14
14
  readonly maxChunkSize?: number;
15
15
  readonly runtime?: MinSyncRuntime;
16
16
  }
17
- /** MinSync v0.4.5 supports native vector, BM25, and hybrid query modes. */
17
+ /** MinSync v0.4.6 supports native vector, BM25, and hybrid query modes. */
18
18
  export type MinSyncQueryMode = "vector" | "bm25" | "hybrid";
19
19
  export declare class MinSyncQueryError extends Error {
20
20
  readonly code: number | null;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * MinSync is the only retrieval method that searches document content
3
+ * semantically, so AutoRAG treats it as required: when it cannot be used there
4
+ * is no degraded mode that answers from other retrieval paths. This error is
5
+ * the one failure that is never swallowed per-method; it ends the operation and
6
+ * reaches the operator with the reason attached.
7
+ */
8
+ export declare class MinSyncRequiredError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ /** Raised when the `minsync` executable cannot be resolved. Path-free on purpose. */
12
+ export declare function minSyncBinaryMissingError(): MinSyncRequiredError;
13
+ /** Raised when auto-install ran and failed; carries the installer's own message. */
14
+ export declare function minSyncInstallFailedError(cause: unknown): MinSyncRequiredError;
@@ -1,5 +1,6 @@
1
1
  export { MINSYNC_OLLAMA_MIGRATION_MESSAGE, MinSyncClient, type MinSyncClientOptions, MinSyncQueryError, type MinSyncQueryMode, } from "./client.js";
2
2
  export { configuredVectorDimension, DEFAULT_MINSYNC_EMBEDDER_CONFIG, DEFAULT_MINSYNC_EMBEDDER_DIMENSION, DEFAULT_MINSYNC_EMBEDDER_ID, MINSYNC_CONFIG_DIR, MINSYNC_CONFIG_FILE, type MinSyncEmbeddingIdentity, minSyncConfigPath, minSyncEmbeddingIdentityPath, rewriteEmbedderConfig, } from "./embedder-config.js";
3
+ export { MinSyncRequiredError } from "./errors.js";
3
4
  export { type EnsureMinSyncBinaryOptions, ensureMinSyncBinary, executableName, fetchLatestMinSyncRelease, type InstalledMinSyncBinary, MINSYNC_VERSION, type MinSyncRelease, type MinSyncReleaseAsset, MinSyncReleaseError, selectReleaseAsset, } from "./installer.js";
4
5
  export { ensureLocalEmbedder, LocalEmbedderError, type LocalEmbedderPreflightOptions, } from "./local-embedder.js";
5
6
  export { MinSyncHybridMethod, type MinSyncHybridMethodOptions, MinSyncVectorMethod, type MinSyncVectorMethodOptions, } from "./method.js";
@@ -1,4 +1,4 @@
1
- export declare const MINSYNC_VERSION = "0.4.5";
1
+ export declare const MINSYNC_VERSION = "0.4.6";
2
2
  export declare const MINSYNC_CARGO_INSTALL_TIMEOUT_MS: number;
3
3
  export interface MinSyncReleaseAsset {
4
4
  readonly name: string;
@@ -50,12 +50,12 @@ export declare class MinSyncVectorMethod implements RetrievalMethod {
50
50
  * auto-install runs only for `sync` (refresh); queries pass
51
51
  * `install: false` so a user's turn never waits on `cargo install`.
52
52
  *
53
- * Returns: string path on success, undefined for missing-binary, or a MinSyncSyncResult
54
- * for install-failed.
53
+ * Returns the executable path, or throws {@link MinSyncRequiredError}:
54
+ * MinSync is required, so there is no "no binary" value to degrade on.
55
55
  */
56
56
  protected resolveBinary(options?: {
57
57
  readonly install?: boolean;
58
- }): Promise<string | undefined | MinSyncSyncResult>;
58
+ }): Promise<string>;
59
59
  }
60
60
  export declare class MinSyncHybridMethod extends MinSyncVectorMethod {
61
61
  constructor(options: MinSyncHybridMethodOptions);
@@ -15,8 +15,11 @@ export interface ParsedMirrorSyncOptions {
15
15
  /** Absolute source paths or directories omitted by the user. */
16
16
  readonly userExcludedSourcePaths?: ReadonlySet<string>;
17
17
  }
18
- export type ParsedMirrorDiagnosticCode = "unsupported-file" | "parser-skipped" | "parser-failed" | "duplicate-excluded" | "deleted-mirror" | "stale-index" | "pdf-extract-thin" | "parser-warning";
19
- /** Path-opaque refresh diagnostic. `source` is an opaque virtual path, never a real fs path. */
18
+ export type ParsedMirrorDiagnosticCode = "unsupported-file" | "parser-skipped" | "parser-failed" | "source-vanished" | "source-unreadable" | "duplicate-excluded" | "deleted-mirror" | "stale-index" | "pdf-extract-thin" | "parser-warning";
19
+ /**
20
+ * Refresh diagnostic. `source` is an opaque virtual path, never a real filesystem path.
21
+ * `message` keeps the underlying error text, which may include a filesystem path.
22
+ */
20
23
  export interface ParsedMirrorDiagnostic {
21
24
  readonly code: ParsedMirrorDiagnosticCode;
22
25
  readonly severity: "info" | "warning";
@@ -9,7 +9,7 @@ export type AutoRAGRunEvent = {
9
9
  timestamp: string;
10
10
  sessionId: string;
11
11
  resultCount: number;
12
- /** True when the run ended without emit_autorag_results and fell back to a degraded response. */
12
+ /** True when the run ended without a final answer message and fell back to a degraded response. */
13
13
  degraded?: boolean;
14
14
  } | {
15
15
  event: "search_failed";
@@ -1,16 +1,27 @@
1
1
  import { type LanguageTag } from "../language.js";
2
2
  import { type KordocParserOptions } from "./kordoc.js";
3
- import { type OcrParserOptions } from "./ocr.js";
3
+ import { type OcrOptions } from "./ocr-engines.js";
4
4
  import { ParserRegistry } from "./registry.js";
5
5
  export interface DefaultParserRegistryOptions {
6
- readonly ocr?: OcrParserOptions;
6
+ readonly ocr?: OcrOptions;
7
7
  readonly kordoc?: KordocParserOptions;
8
- /** Global document languages; drives OCR engine selection. */
8
+ /** Global document languages; selects the OCR engine when OCR is enabled. */
9
9
  readonly languages?: readonly LanguageTag[];
10
10
  }
11
+ /** Workspace-relative directory for Tesseract traineddata, so models never land in the process working directory. */
12
+ export declare function tesseractCachePathFor(workspacePath: string): string;
11
13
  /**
12
14
  * Merges the globally configured document languages into registry options.
13
- * An explicit `parserOptions.languages` wins over the global setting.
15
+ * An explicit `parserOptions.languages` wins over the global setting. When a
16
+ * workspace is known, Tesseract's model cache is pinned under it unless the
17
+ * caller set `ocr.cachePath`.
18
+ */
19
+ export declare function resolveParserOptions(parserOptions: DefaultParserRegistryOptions | undefined, languages: readonly LanguageTag[], workspacePath?: string): DefaultParserRegistryOptions;
20
+ /**
21
+ * `ocr.enabled` is the single opt-in. Off: image files are not parsed and
22
+ * scanned pages are left unrecognized. On: kordoc owns both, and the
23
+ * configured languages pick the engine. kordoc's built-in PP-OCRv5 model is
24
+ * used only when every language is one it reads reliably; otherwise Tesseract
25
+ * is injected as kordoc's OCR provider. An explicit `kordoc.ocr` always wins.
14
26
  */
15
- export declare function resolveParserOptions(parserOptions: DefaultParserRegistryOptions | undefined, languages: readonly LanguageTag[]): DefaultParserRegistryOptions;
16
27
  export declare function createDefaultParserRegistry(options?: DefaultParserRegistryOptions): ParserRegistry;
@@ -2,7 +2,7 @@ export { createDefaultParserRegistry, type DefaultParserRegistryOptions, resolve
2
2
  export { EmlParser } from "./eml.js";
3
3
  export { ParseError } from "./errors.js";
4
4
  export { KORDOC_EXTENSIONS, type KordocOcrProvider, type KordocParseFn, KordocParser, type KordocParserOptions, } from "./kordoc.js";
5
- export { ImageOcrParser, type OcrEngine, type OcrEngineInput, type OcrParserOptions } from "./ocr.js";
5
+ export { BUILTIN_OCR_LANGUAGES, createTesseractOcrProvider, type OcrOptions, type OcrProvider, } from "./ocr-engines.js";
6
6
  export { PptxParser } from "./office.js";
7
7
  export { PlainTextParser } from "./plain-text.js";
8
8
  export { ParserRegistry } from "./registry.js";
@@ -33,10 +33,17 @@ export type KordocParseFn = (bytes: Uint8Array, options: KordocParseCallOptions)
33
33
  export interface KordocParserOptions {
34
34
  /** OCR mode handed to kordoc: off, built-in engine, or an injected provider. */
35
35
  readonly ocr?: boolean | "force" | KordocOcrProvider;
36
+ /** Also claim standalone image files; kordoc OCRs them whenever it parses them, so this follows the OCR switch. */
37
+ readonly images?: boolean;
36
38
  readonly parse?: KordocParseFn;
37
39
  }
38
40
  /** Document extensions kordoc parses. `.pptx` and `.eml` stay on their own parsers. */
39
41
  export declare const KORDOC_EXTENSIONS: readonly [".hwp", ".hwpx", ".hml", ".hwpml", ".pdf", ".docx", ".xlsx", ".xls"];
42
+ /**
43
+ * Standalone image formats kordoc OCRs directly. `.bmp` and `.tiff` return
44
+ * `UNSUPPORTED_FORMAT` from kordoc, so they are deliberately not claimed.
45
+ */
46
+ export declare const KORDOC_IMAGE_EXTENSIONS: readonly [".png", ".jpg", ".jpeg", ".webp"];
40
47
  /**
41
48
  * Parses HWP/HWPX/HWPML, PDF, DOCX and XLSX/XLS through the kordoc library.
42
49
  *
@@ -47,7 +54,7 @@ export declare const KORDOC_EXTENSIONS: readonly [".hwp", ".hwpx", ".hml", ".hwp
47
54
  export declare class KordocParser extends Parser {
48
55
  #private;
49
56
  readonly name = "kordoc";
50
- readonly extensions: readonly [".hwp", ".hwpx", ".hml", ".hwpml", ".pdf", ".docx", ".xlsx", ".xls"];
57
+ readonly extensions: readonly string[];
51
58
  constructor(options?: KordocParserOptions);
52
59
  parse(input: ParseInput): Promise<ParseOutput>;
53
60
  }
@@ -1,9 +1,28 @@
1
1
  import type { LanguageTag } from "../language.js";
2
+ /**
3
+ * Languages kordoc's built-in PP-OCRv5 model reads reliably. Its recognizer
4
+ * dictionary is Korean plus basic Latin: it has no kana, han, Cyrillic, Thai,
5
+ * Arabic or Devanagari, and on rendered text it drops diacritics (accented
6
+ * character recall fr 0.64, de 0.82, es 0.45 versus Tesseract 1.00, 0.91, 1.00).
7
+ * Any configured language outside this set switches OCR to Tesseract.
8
+ */
9
+ export declare const BUILTIN_OCR_LANGUAGES: ReadonlySet<LanguageTag>;
10
+ /** OCR switch and Tesseract settings. `enabled` is the single opt-in for image files and scanned pages. */
11
+ export interface OcrOptions {
12
+ readonly enabled: boolean;
13
+ readonly timeoutMs?: number;
14
+ /**
15
+ * Directory where Tesseract stores downloaded traineddata. tesseract.js
16
+ * falls back to the process working directory when unset.
17
+ */
18
+ readonly cachePath?: string;
19
+ }
2
20
  export type OcrProvider = (pageImage: Uint8Array, pageNumber: number, mimeType: "image/png" | "image/jpeg" | "image/webp") => Promise<string>;
3
21
  export type TesseractOcrEngine = (language: string, pageImage: Uint8Array, pageNumber: number, mimeType: "image/png" | "image/jpeg" | "image/webp") => Promise<string>;
4
22
  export interface TesseractOcrProviderOptions {
5
23
  readonly languages: readonly LanguageTag[];
6
24
  readonly timeoutMs?: number;
25
+ readonly cachePath?: string;
7
26
  readonly engine?: TesseractOcrEngine;
8
27
  }
9
28
  /** Traineddata codes for the configured languages, order preserved and deduplicated. */
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Lightweight BM25-style lexical scorer shared by retrieval surfaces.
3
+ *
4
+ * Terms match document tokens exactly or as a prefix (min 2 chars), so
5
+ * agglutinative suffixes — Korean particles/endings (인증서 → 인증서를) and
6
+ * English inflections (index → indexing) — still rank. Prefix hits are
7
+ * slightly discounted against exact hits (0.75 weight).
8
+ */
9
+ /**
10
+ * Lowercase `text` and split on anything that is not a letter, digit, or
11
+ * Hangul syllable, discarding empty tokens.
12
+ */
13
+ export declare function tokenize(text: string): string[];
14
+ /**
15
+ * Score each entry of `documents` against `query` with a BM25-style formula.
16
+ * Returns one score per document, in the same order; unmatched documents
17
+ * score 0. Empty query terms or zero documents yield an array of zeros.
18
+ */
19
+ export declare function bm25Scores(query: string, documents: readonly string[]): number[];