@lov3kaizen/agentsea-memory 0.5.1
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/LICENSE +21 -0
- package/README.md +450 -0
- package/dist/chunk-GACX3FPR.js +1402 -0
- package/dist/chunk-M44NB53O.js +1226 -0
- package/dist/chunk-MQDWBPZU.js +972 -0
- package/dist/chunk-TPC7MYWK.js +1495 -0
- package/dist/chunk-XD2CQGSD.js +1540 -0
- package/dist/chunk-YI7RPDEV.js +1215 -0
- package/dist/core.types-lkxKv-bW.d.cts +242 -0
- package/dist/core.types-lkxKv-bW.d.ts +242 -0
- package/dist/debug/index.cjs +1248 -0
- package/dist/debug/index.d.cts +3 -0
- package/dist/debug/index.d.ts +3 -0
- package/dist/debug/index.js +20 -0
- package/dist/index-7SsAJ4et.d.ts +525 -0
- package/dist/index-BGxYqpFb.d.cts +601 -0
- package/dist/index-BX62efZu.d.ts +565 -0
- package/dist/index-Bbc3COw0.d.cts +748 -0
- package/dist/index-Bczz1Eyk.d.ts +637 -0
- package/dist/index-C7pEiT8L.d.cts +637 -0
- package/dist/index-CHetLTb0.d.ts +389 -0
- package/dist/index-CloeiFyx.d.ts +748 -0
- package/dist/index-DNOhq-3y.d.cts +525 -0
- package/dist/index-Da-M8FOV.d.cts +389 -0
- package/dist/index-Dy8UjRFz.d.cts +565 -0
- package/dist/index-aVcITW0B.d.ts +601 -0
- package/dist/index.cjs +8554 -0
- package/dist/index.d.cts +293 -0
- package/dist/index.d.ts +293 -0
- package/dist/index.js +742 -0
- package/dist/processing/index.cjs +1575 -0
- package/dist/processing/index.d.cts +2 -0
- package/dist/processing/index.d.ts +2 -0
- package/dist/processing/index.js +24 -0
- package/dist/retrieval/index.cjs +1262 -0
- package/dist/retrieval/index.d.cts +2 -0
- package/dist/retrieval/index.d.ts +2 -0
- package/dist/retrieval/index.js +26 -0
- package/dist/sharing/index.cjs +1003 -0
- package/dist/sharing/index.d.cts +3 -0
- package/dist/sharing/index.d.ts +3 -0
- package/dist/sharing/index.js +16 -0
- package/dist/stores/index.cjs +1445 -0
- package/dist/stores/index.d.cts +2 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/stores/index.js +20 -0
- package/dist/structures/index.cjs +1530 -0
- package/dist/structures/index.d.cts +3 -0
- package/dist/structures/index.d.ts +3 -0
- package/dist/structures/index.js +24 -0
- package/package.json +141 -0
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
import { S as ScoredMemory, c as MemoryEntry, i as MemoryStoreInterface } from './core.types-lkxKv-bW.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieval Types
|
|
5
|
+
*
|
|
6
|
+
* Types for memory retrieval strategies.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Semantic retrieval configuration
|
|
11
|
+
*/
|
|
12
|
+
interface SemanticRetrievalConfig {
|
|
13
|
+
topK?: number;
|
|
14
|
+
minScore?: number;
|
|
15
|
+
reranking?: boolean;
|
|
16
|
+
rerankModel?: string;
|
|
17
|
+
maxCandidates?: number;
|
|
18
|
+
rerankFn?: (query: string, results: ScoredMemory[]) => Promise<ScoredMemory[]>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Keyword retrieval configuration
|
|
22
|
+
*/
|
|
23
|
+
interface KeywordRetrievalConfig {
|
|
24
|
+
analyzer?: 'english' | 'standard' | 'simple';
|
|
25
|
+
fuzziness?: number;
|
|
26
|
+
boost?: Record<string, number>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hybrid retrieval configuration
|
|
30
|
+
*/
|
|
31
|
+
interface HybridRetrievalConfig {
|
|
32
|
+
semanticWeight?: number;
|
|
33
|
+
keywordWeight?: number;
|
|
34
|
+
topK?: number;
|
|
35
|
+
minScore?: number;
|
|
36
|
+
fusionMethod?: 'rrf' | 'weighted-sum' | 'max' | 'reciprocal-rank';
|
|
37
|
+
semantic?: {
|
|
38
|
+
weight: number;
|
|
39
|
+
config?: SemanticRetrievalConfig;
|
|
40
|
+
};
|
|
41
|
+
keyword?: {
|
|
42
|
+
weight: number;
|
|
43
|
+
config?: KeywordRetrievalConfig;
|
|
44
|
+
};
|
|
45
|
+
fusion?: 'reciprocal-rank' | 'weighted-sum' | 'max';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Temporal decay function
|
|
49
|
+
*/
|
|
50
|
+
type TemporalDecayFunction = 'exponential' | 'linear' | 'step' | 'logarithmic' | 'custom';
|
|
51
|
+
/**
|
|
52
|
+
* Temporal retrieval configuration
|
|
53
|
+
*/
|
|
54
|
+
interface TemporalRetrievalConfig {
|
|
55
|
+
decayFunction?: TemporalDecayFunction;
|
|
56
|
+
halfLife?: number;
|
|
57
|
+
customDecay?: (ageMs: number) => number;
|
|
58
|
+
boost?: {
|
|
59
|
+
recent?: number;
|
|
60
|
+
medium?: number;
|
|
61
|
+
old?: number;
|
|
62
|
+
};
|
|
63
|
+
recentThreshold?: number;
|
|
64
|
+
mediumThreshold?: number;
|
|
65
|
+
recencyWeight?: number;
|
|
66
|
+
importanceWeight?: number;
|
|
67
|
+
accessWeight?: number;
|
|
68
|
+
decayHalfLife?: number;
|
|
69
|
+
topK?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Reranker interface
|
|
73
|
+
*/
|
|
74
|
+
interface RerankerInterface {
|
|
75
|
+
readonly name: string;
|
|
76
|
+
rerank(query: string, candidates: ScoredMemory[], topK: number): Promise<ScoredMemory[]>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Retrieval pipeline stage
|
|
80
|
+
*/
|
|
81
|
+
interface RetrievalPipelineStage {
|
|
82
|
+
stage: string;
|
|
83
|
+
retriever?: {
|
|
84
|
+
retrieve(query: string, context: RetrievalPipelineContext): Promise<ScoredMemory[]>;
|
|
85
|
+
};
|
|
86
|
+
filter?: (memory: MemoryEntry) => boolean;
|
|
87
|
+
reranker?: RerankerInterface;
|
|
88
|
+
transform?: (memories: ScoredMemory[]) => ScoredMemory[];
|
|
89
|
+
topK?: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Retrieval pipeline configuration
|
|
93
|
+
*/
|
|
94
|
+
interface RetrievalPipelineConfig {
|
|
95
|
+
stages: RetrievalPipelineStage[];
|
|
96
|
+
fallback?: 'previous-stage' | 'empty' | 'error';
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Retrieval pipeline context
|
|
100
|
+
*/
|
|
101
|
+
interface RetrievalPipelineContext {
|
|
102
|
+
query: string;
|
|
103
|
+
embedding?: number[];
|
|
104
|
+
filters?: Record<string, unknown>;
|
|
105
|
+
limit?: number;
|
|
106
|
+
metadata?: Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Retrieval result
|
|
110
|
+
*/
|
|
111
|
+
interface RetrievalResult {
|
|
112
|
+
memories: MemoryEntry[];
|
|
113
|
+
scores: number[];
|
|
114
|
+
totalCandidates: number;
|
|
115
|
+
retrievalTimeMs: number;
|
|
116
|
+
strategy: string;
|
|
117
|
+
metadata?: Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Retrieval result with debug info
|
|
121
|
+
*/
|
|
122
|
+
interface RetrievalResultWithDebug {
|
|
123
|
+
results: ScoredMemory[];
|
|
124
|
+
debug?: {
|
|
125
|
+
queryEmbedding?: number[];
|
|
126
|
+
stages?: Array<{
|
|
127
|
+
name: string;
|
|
128
|
+
inputCount: number;
|
|
129
|
+
outputCount: number;
|
|
130
|
+
durationMs: number;
|
|
131
|
+
}>;
|
|
132
|
+
totalDurationMs: number;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* SemanticRetrieval
|
|
138
|
+
*
|
|
139
|
+
* Vector-based semantic search retrieval strategy.
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Embedding function type
|
|
144
|
+
*/
|
|
145
|
+
type EmbeddingFunction = (text: string) => Promise<number[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Semantic retrieval options
|
|
148
|
+
*/
|
|
149
|
+
interface SemanticRetrievalOptions {
|
|
150
|
+
query: string;
|
|
151
|
+
topK?: number;
|
|
152
|
+
minScore?: number;
|
|
153
|
+
namespace?: string;
|
|
154
|
+
filter?: Record<string, unknown>;
|
|
155
|
+
includeEmbeddings?: boolean;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Semantic retrieval strategy using vector embeddings
|
|
159
|
+
*/
|
|
160
|
+
declare class SemanticRetrieval {
|
|
161
|
+
private store;
|
|
162
|
+
private embedFn;
|
|
163
|
+
private config;
|
|
164
|
+
constructor(store: MemoryStoreInterface, embedFn: EmbeddingFunction, config?: SemanticRetrievalConfig);
|
|
165
|
+
/**
|
|
166
|
+
* Retrieve memories semantically similar to the query
|
|
167
|
+
*/
|
|
168
|
+
retrieve(options: SemanticRetrievalOptions): Promise<RetrievalResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Retrieve with context - includes surrounding memories
|
|
171
|
+
*/
|
|
172
|
+
retrieveWithContext(options: SemanticRetrievalOptions, contextWindow?: number): Promise<RetrievalResult & {
|
|
173
|
+
contextMemories: MemoryEntry[][];
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* Get memories surrounding a given memory by timestamp
|
|
177
|
+
*/
|
|
178
|
+
private getSurroundingMemories;
|
|
179
|
+
/**
|
|
180
|
+
* Rerank results using provided rerank function
|
|
181
|
+
*/
|
|
182
|
+
private rerank;
|
|
183
|
+
/**
|
|
184
|
+
* Find memories similar to a given memory
|
|
185
|
+
*/
|
|
186
|
+
findSimilar(memory: MemoryEntry, options?: Partial<SemanticRetrievalOptions>): Promise<ScoredMemory[]>;
|
|
187
|
+
/**
|
|
188
|
+
* Cluster memories by semantic similarity
|
|
189
|
+
*/
|
|
190
|
+
cluster(memories: MemoryEntry[], numClusters?: number): Promise<Map<number, MemoryEntry[]>>;
|
|
191
|
+
/**
|
|
192
|
+
* Calculate cosine similarity between two vectors
|
|
193
|
+
*/
|
|
194
|
+
private cosineSimilarity;
|
|
195
|
+
/**
|
|
196
|
+
* Calculate average embedding
|
|
197
|
+
*/
|
|
198
|
+
private averageEmbedding;
|
|
199
|
+
/**
|
|
200
|
+
* Random sample without replacement
|
|
201
|
+
*/
|
|
202
|
+
private randomSample;
|
|
203
|
+
/**
|
|
204
|
+
* Update configuration
|
|
205
|
+
*/
|
|
206
|
+
configure(config: Partial<SemanticRetrievalConfig>): void;
|
|
207
|
+
/**
|
|
208
|
+
* Get current configuration
|
|
209
|
+
*/
|
|
210
|
+
getConfig(): SemanticRetrievalConfig;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Create a semantic retrieval instance
|
|
214
|
+
*/
|
|
215
|
+
declare function createSemanticRetrieval(store: MemoryStoreInterface, embedFn: EmbeddingFunction, config?: SemanticRetrievalConfig): SemanticRetrieval;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* HybridRetrieval
|
|
219
|
+
*
|
|
220
|
+
* Combines semantic search with keyword matching for better recall.
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Hybrid retrieval options
|
|
225
|
+
*/
|
|
226
|
+
interface HybridRetrievalOptions {
|
|
227
|
+
query: string;
|
|
228
|
+
topK?: number;
|
|
229
|
+
minScore?: number;
|
|
230
|
+
namespace?: string;
|
|
231
|
+
filter?: Record<string, unknown>;
|
|
232
|
+
semanticWeight?: number;
|
|
233
|
+
keywordWeight?: number;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Hybrid retrieval strategy combining semantic and keyword search
|
|
237
|
+
*/
|
|
238
|
+
declare class HybridRetrieval {
|
|
239
|
+
private store;
|
|
240
|
+
private semanticRetrieval;
|
|
241
|
+
private config;
|
|
242
|
+
constructor(store: MemoryStoreInterface, embedFn: EmbeddingFunction, config?: HybridRetrievalConfig);
|
|
243
|
+
/**
|
|
244
|
+
* Retrieve memories using hybrid search
|
|
245
|
+
*/
|
|
246
|
+
retrieve(options: HybridRetrievalOptions): Promise<RetrievalResult>;
|
|
247
|
+
/**
|
|
248
|
+
* Keyword-based search using text matching
|
|
249
|
+
*/
|
|
250
|
+
private keywordSearch;
|
|
251
|
+
/**
|
|
252
|
+
* Tokenize text into terms
|
|
253
|
+
*/
|
|
254
|
+
private tokenize;
|
|
255
|
+
/**
|
|
256
|
+
* Calculate BM25-like keyword score
|
|
257
|
+
*/
|
|
258
|
+
private calculateKeywordScore;
|
|
259
|
+
/**
|
|
260
|
+
* Fuse semantic and keyword results
|
|
261
|
+
*/
|
|
262
|
+
private fuseResults;
|
|
263
|
+
/**
|
|
264
|
+
* Reciprocal Rank Fusion (RRF)
|
|
265
|
+
*/
|
|
266
|
+
private reciprocalRankFusion;
|
|
267
|
+
/**
|
|
268
|
+
* Weighted score fusion
|
|
269
|
+
*/
|
|
270
|
+
private weightedFusion;
|
|
271
|
+
/**
|
|
272
|
+
* Retrieve with explanation of why each result matched
|
|
273
|
+
*/
|
|
274
|
+
retrieveWithExplanation(options: HybridRetrievalOptions): Promise<RetrievalResult & {
|
|
275
|
+
explanations: string[];
|
|
276
|
+
}>;
|
|
277
|
+
/**
|
|
278
|
+
* Update configuration
|
|
279
|
+
*/
|
|
280
|
+
configure(config: Partial<HybridRetrievalConfig>): void;
|
|
281
|
+
/**
|
|
282
|
+
* Get current configuration
|
|
283
|
+
*/
|
|
284
|
+
getConfig(): HybridRetrievalConfig;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Create a hybrid retrieval instance
|
|
288
|
+
*/
|
|
289
|
+
declare function createHybridRetrieval(store: MemoryStoreInterface, embedFn: EmbeddingFunction, config?: HybridRetrievalConfig): HybridRetrieval;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* TemporalRetrieval
|
|
293
|
+
*
|
|
294
|
+
* Time-based memory retrieval with recency weighting and temporal patterns.
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Temporal retrieval options
|
|
299
|
+
*/
|
|
300
|
+
interface TemporalRetrievalOptions {
|
|
301
|
+
startTime?: number;
|
|
302
|
+
endTime?: number;
|
|
303
|
+
topK?: number;
|
|
304
|
+
recencyWeight?: number;
|
|
305
|
+
importanceWeight?: number;
|
|
306
|
+
accessWeight?: number;
|
|
307
|
+
namespace?: string;
|
|
308
|
+
types?: string[];
|
|
309
|
+
filter?: Record<string, unknown>;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Time window definition
|
|
313
|
+
*/
|
|
314
|
+
interface TimeWindow {
|
|
315
|
+
start: number;
|
|
316
|
+
end: number;
|
|
317
|
+
label?: string;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Temporal pattern
|
|
321
|
+
*/
|
|
322
|
+
interface TemporalPattern {
|
|
323
|
+
type: 'daily' | 'weekly' | 'monthly' | 'custom';
|
|
324
|
+
interval: number;
|
|
325
|
+
peakHours?: number[];
|
|
326
|
+
peakDays?: number[];
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Temporal retrieval strategy with time-based scoring
|
|
330
|
+
*/
|
|
331
|
+
declare class TemporalRetrieval {
|
|
332
|
+
private store;
|
|
333
|
+
private config;
|
|
334
|
+
constructor(store: MemoryStoreInterface, config?: TemporalRetrievalConfig);
|
|
335
|
+
/**
|
|
336
|
+
* Retrieve memories with temporal scoring
|
|
337
|
+
*/
|
|
338
|
+
retrieve(options: TemporalRetrievalOptions): Promise<RetrievalResult>;
|
|
339
|
+
/**
|
|
340
|
+
* Retrieve memories from specific time windows
|
|
341
|
+
*/
|
|
342
|
+
retrieveFromWindows(windows: TimeWindow[], options?: Partial<TemporalRetrievalOptions>): Promise<Map<string, RetrievalResult>>;
|
|
343
|
+
/**
|
|
344
|
+
* Get memories from relative time periods
|
|
345
|
+
*/
|
|
346
|
+
retrieveRecent(period: 'hour' | 'day' | 'week' | 'month', options?: Partial<TemporalRetrievalOptions>): Promise<RetrievalResult>;
|
|
347
|
+
/**
|
|
348
|
+
* Get trending memories (high access in recent time)
|
|
349
|
+
*/
|
|
350
|
+
retrieveTrending(windowMs?: number, options?: Partial<TemporalRetrievalOptions>): Promise<RetrievalResult>;
|
|
351
|
+
/**
|
|
352
|
+
* Get memories matching a temporal pattern
|
|
353
|
+
*/
|
|
354
|
+
retrieveByPattern(pattern: TemporalPattern, lookbackPeriods?: number, options?: Partial<TemporalRetrievalOptions>): Promise<RetrievalResult>;
|
|
355
|
+
/**
|
|
356
|
+
* Get timeline of memories
|
|
357
|
+
*/
|
|
358
|
+
getTimeline(options: {
|
|
359
|
+
startTime: number;
|
|
360
|
+
endTime: number;
|
|
361
|
+
bucketSize: 'hour' | 'day' | 'week';
|
|
362
|
+
namespace?: string;
|
|
363
|
+
}): Promise<Map<string, MemoryEntry[]>>;
|
|
364
|
+
/**
|
|
365
|
+
* Calculate temporal score for a memory
|
|
366
|
+
*/
|
|
367
|
+
private calculateTemporalScore;
|
|
368
|
+
/**
|
|
369
|
+
* Calculate decay based on configured function
|
|
370
|
+
*/
|
|
371
|
+
private calculateDecay;
|
|
372
|
+
/**
|
|
373
|
+
* Apply metadata filter to entries
|
|
374
|
+
*/
|
|
375
|
+
private applyFilter;
|
|
376
|
+
/**
|
|
377
|
+
* Deduplicate entries by ID
|
|
378
|
+
*/
|
|
379
|
+
private deduplicateEntries;
|
|
380
|
+
/**
|
|
381
|
+
* Update configuration
|
|
382
|
+
*/
|
|
383
|
+
configure(config: Partial<TemporalRetrievalConfig>): void;
|
|
384
|
+
/**
|
|
385
|
+
* Get current configuration
|
|
386
|
+
*/
|
|
387
|
+
getConfig(): TemporalRetrievalConfig;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Create a temporal retrieval instance
|
|
391
|
+
*/
|
|
392
|
+
declare function createTemporalRetrieval(store: MemoryStoreInterface, config?: TemporalRetrievalConfig): TemporalRetrieval;
|
|
393
|
+
/**
|
|
394
|
+
* Helper to create common time windows
|
|
395
|
+
*/
|
|
396
|
+
declare const TimeWindows: {
|
|
397
|
+
lastHour: () => TimeWindow;
|
|
398
|
+
lastDay: () => TimeWindow;
|
|
399
|
+
lastWeek: () => TimeWindow;
|
|
400
|
+
lastMonth: () => TimeWindow;
|
|
401
|
+
today: () => TimeWindow;
|
|
402
|
+
yesterday: () => TimeWindow;
|
|
403
|
+
custom: (startDate: Date, endDate: Date, label?: string) => TimeWindow;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* RetrievalPipeline
|
|
408
|
+
*
|
|
409
|
+
* Chains multiple retrieval strategies together with configurable stages.
|
|
410
|
+
*/
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Pipeline stage function type
|
|
414
|
+
*/
|
|
415
|
+
type PipelineStage = (input: PipelineContext, config: StageConfig) => Promise<PipelineContext>;
|
|
416
|
+
/**
|
|
417
|
+
* Stage configuration
|
|
418
|
+
*/
|
|
419
|
+
interface StageConfig {
|
|
420
|
+
name: string;
|
|
421
|
+
enabled?: boolean;
|
|
422
|
+
params?: Record<string, unknown>;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Pipeline context passed between stages
|
|
426
|
+
*/
|
|
427
|
+
interface PipelineContext {
|
|
428
|
+
query: string;
|
|
429
|
+
candidates: ScoredMemory[];
|
|
430
|
+
metadata: Record<string, unknown>;
|
|
431
|
+
timing: Record<string, number>;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Pipeline configuration
|
|
435
|
+
*/
|
|
436
|
+
interface PipelineConfig {
|
|
437
|
+
stages: StageConfig[];
|
|
438
|
+
maxCandidates?: number;
|
|
439
|
+
minScore?: number;
|
|
440
|
+
timeout?: number;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Built-in stage types
|
|
444
|
+
*/
|
|
445
|
+
type BuiltInStage = 'filter' | 'boost' | 'rerank' | 'dedupe' | 'diversify' | 'truncate' | 'enrich';
|
|
446
|
+
/**
|
|
447
|
+
* Retrieval pipeline for chaining retrieval strategies
|
|
448
|
+
*/
|
|
449
|
+
declare class RetrievalPipeline {
|
|
450
|
+
private stages;
|
|
451
|
+
private config;
|
|
452
|
+
constructor(config?: PipelineConfig);
|
|
453
|
+
/**
|
|
454
|
+
* Register built-in stages
|
|
455
|
+
*/
|
|
456
|
+
private registerBuiltInStages;
|
|
457
|
+
/**
|
|
458
|
+
* Register a custom stage
|
|
459
|
+
*/
|
|
460
|
+
register(name: string, stage: PipelineStage): void;
|
|
461
|
+
/**
|
|
462
|
+
* Execute the pipeline
|
|
463
|
+
*/
|
|
464
|
+
execute(query: string, initialCandidates: ScoredMemory[]): Promise<RetrievalResult>;
|
|
465
|
+
/**
|
|
466
|
+
* Execute promise with timeout
|
|
467
|
+
*/
|
|
468
|
+
private executeWithTimeout;
|
|
469
|
+
/**
|
|
470
|
+
* Get dedupe key for an entry
|
|
471
|
+
*/
|
|
472
|
+
private getDedupeKey;
|
|
473
|
+
/**
|
|
474
|
+
* Add a stage to the pipeline
|
|
475
|
+
*/
|
|
476
|
+
addStage(config: StageConfig): this;
|
|
477
|
+
/**
|
|
478
|
+
* Remove a stage from the pipeline
|
|
479
|
+
*/
|
|
480
|
+
removeStage(name: string): this;
|
|
481
|
+
/**
|
|
482
|
+
* Update pipeline configuration
|
|
483
|
+
*/
|
|
484
|
+
configure(config: Partial<PipelineConfig>): void;
|
|
485
|
+
/**
|
|
486
|
+
* Get current configuration
|
|
487
|
+
*/
|
|
488
|
+
getConfig(): PipelineConfig;
|
|
489
|
+
/**
|
|
490
|
+
* Get registered stage names
|
|
491
|
+
*/
|
|
492
|
+
getStageNames(): string[];
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Pipeline builder for fluent API
|
|
496
|
+
*/
|
|
497
|
+
declare class PipelineBuilder {
|
|
498
|
+
private stages;
|
|
499
|
+
private maxCandidates;
|
|
500
|
+
private minScore;
|
|
501
|
+
private timeout;
|
|
502
|
+
private customStages;
|
|
503
|
+
/**
|
|
504
|
+
* Add a filter stage
|
|
505
|
+
*/
|
|
506
|
+
filter(filters: Record<string, unknown>): this;
|
|
507
|
+
/**
|
|
508
|
+
* Add a boost stage
|
|
509
|
+
*/
|
|
510
|
+
boost(boosts: Array<{
|
|
511
|
+
field: string;
|
|
512
|
+
value: unknown;
|
|
513
|
+
factor: number;
|
|
514
|
+
}>): this;
|
|
515
|
+
/**
|
|
516
|
+
* Add a rerank stage
|
|
517
|
+
*/
|
|
518
|
+
rerank(weights: Record<string, number>): this;
|
|
519
|
+
/**
|
|
520
|
+
* Add a dedupe stage
|
|
521
|
+
*/
|
|
522
|
+
dedupe(field?: string, similarity?: number): this;
|
|
523
|
+
/**
|
|
524
|
+
* Add a diversify stage
|
|
525
|
+
*/
|
|
526
|
+
diversify(field?: string, maxPerCategory?: number): this;
|
|
527
|
+
/**
|
|
528
|
+
* Add a truncate stage
|
|
529
|
+
*/
|
|
530
|
+
truncate(limit: number): this;
|
|
531
|
+
/**
|
|
532
|
+
* Add an enrich stage
|
|
533
|
+
*/
|
|
534
|
+
enrich(enrichFn: (entry: MemoryEntry) => Promise<Record<string, unknown>>): this;
|
|
535
|
+
/**
|
|
536
|
+
* Add a custom stage
|
|
537
|
+
*/
|
|
538
|
+
custom(name: string, stage: PipelineStage, params?: Record<string, unknown>): this;
|
|
539
|
+
/**
|
|
540
|
+
* Set maximum candidates
|
|
541
|
+
*/
|
|
542
|
+
withMaxCandidates(max: number): this;
|
|
543
|
+
/**
|
|
544
|
+
* Set minimum score
|
|
545
|
+
*/
|
|
546
|
+
withMinScore(min: number): this;
|
|
547
|
+
/**
|
|
548
|
+
* Set timeout
|
|
549
|
+
*/
|
|
550
|
+
withTimeout(ms: number): this;
|
|
551
|
+
/**
|
|
552
|
+
* Build the pipeline
|
|
553
|
+
*/
|
|
554
|
+
build(): RetrievalPipeline;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Create a pipeline builder
|
|
558
|
+
*/
|
|
559
|
+
declare function createPipelineBuilder(): PipelineBuilder;
|
|
560
|
+
/**
|
|
561
|
+
* Create a retrieval pipeline
|
|
562
|
+
*/
|
|
563
|
+
declare function createRetrievalPipeline(config?: PipelineConfig): RetrievalPipeline;
|
|
564
|
+
|
|
565
|
+
export { type BuiltInStage as B, type EmbeddingFunction as E, type HybridRetrievalConfig as H, PipelineBuilder as P, type RetrievalPipelineConfig as R, type SemanticRetrievalConfig as S, type TemporalRetrievalConfig as T, type RetrievalResultWithDebug as a, SemanticRetrieval as b, createSemanticRetrieval as c, HybridRetrieval as d, createHybridRetrieval as e, TemporalRetrieval as f, createTemporalRetrieval as g, TimeWindows as h, RetrievalPipeline as i, createRetrievalPipeline as j, createPipelineBuilder as k, type SemanticRetrievalOptions as l, type HybridRetrievalOptions as m, type TemporalRetrievalOptions as n, type TimeWindow as o, type TemporalPattern as p, type PipelineStage as q, type StageConfig as r, type PipelineContext as s, type PipelineConfig as t };
|