@ruvector/ruvllm 2.6.2 → 3.0.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/README.md +144 -38
- package/bin/cli.js +38 -18
- package/dist/cjs/engine.d.ts +79 -12
- package/dist/cjs/engine.d.ts.map +1 -1
- package/dist/cjs/engine.js +264 -55
- package/dist/cjs/native.d.ts +54 -6
- package/dist/cjs/native.d.ts.map +1 -1
- package/dist/cjs/native.js +30 -9
- package/dist/cjs/types.d.ts +95 -7
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +1 -1
- package/dist/esm/engine.d.ts +79 -12
- package/dist/esm/engine.d.ts.map +1 -1
- package/dist/esm/engine.js +263 -54
- package/dist/esm/native.d.ts +54 -6
- package/dist/esm/native.d.ts.map +1 -1
- package/dist/esm/native.js +31 -10
- package/dist/esm/types.d.ts +95 -7
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +1 -1
- package/package.json +4 -3
- package/dist/cjs/rlm/controller.d.ts +0 -245
- package/dist/cjs/rlm/controller.d.ts.map +0 -1
- package/dist/cjs/rlm/controller.js +0 -554
- package/dist/cjs/rlm/index.d.ts +0 -62
- package/dist/cjs/rlm/index.d.ts.map +0 -1
- package/dist/cjs/rlm/index.js +0 -97
- package/dist/cjs/rlm/training.d.ts +0 -333
- package/dist/cjs/rlm/training.d.ts.map +0 -1
- package/dist/cjs/rlm/training.js +0 -680
- package/dist/cjs/rlm/types.d.ts +0 -189
- package/dist/cjs/rlm/types.d.ts.map +0 -1
- package/dist/cjs/rlm/types.js +0 -10
- package/dist/esm/rlm/controller.d.ts +0 -245
- package/dist/esm/rlm/controller.d.ts.map +0 -1
- package/dist/esm/rlm/controller.js +0 -550
- package/dist/esm/rlm/index.d.ts +0 -62
- package/dist/esm/rlm/index.d.ts.map +0 -1
- package/dist/esm/rlm/index.js +0 -71
- package/dist/esm/rlm/training.d.ts +0 -333
- package/dist/esm/rlm/training.d.ts.map +0 -1
- package/dist/esm/rlm/training.js +0 -672
- package/dist/esm/rlm/types.d.ts +0 -189
- package/dist/esm/rlm/types.d.ts.map +0 -1
- package/dist/esm/rlm/types.js +0 -9
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RLM Controller - Recursive Retrieval Language Model
|
|
3
|
-
*
|
|
4
|
-
* Implements a recursive retrieval-augmented generation system that:
|
|
5
|
-
* 1. Breaks down complex queries into sub-queries
|
|
6
|
-
* 2. Retrieves relevant memory spans for each query
|
|
7
|
-
* 3. Synthesizes coherent answers from retrieved context
|
|
8
|
-
* 4. Optionally reflects on and refines answers
|
|
9
|
-
*
|
|
10
|
-
* @example Basic Usage
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { RlmController } from '@ruvector/ruvllm';
|
|
13
|
-
*
|
|
14
|
-
* const rlm = new RlmController({
|
|
15
|
-
* maxDepth: 3,
|
|
16
|
-
* retrievalTopK: 10,
|
|
17
|
-
* enableCache: true,
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
* // Add knowledge to memory
|
|
21
|
-
* await rlm.addMemory('Machine learning is a subset of AI that enables systems to learn from data.');
|
|
22
|
-
* await rlm.addMemory('Deep learning uses neural networks with many layers.');
|
|
23
|
-
*
|
|
24
|
-
* // Query with recursive retrieval
|
|
25
|
-
* const answer = await rlm.query('Explain the relationship between ML and deep learning');
|
|
26
|
-
* console.log(answer.text);
|
|
27
|
-
* console.log('Sources:', answer.sources.length);
|
|
28
|
-
* console.log('Confidence:', answer.confidence);
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @example Streaming
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const rlm = new RlmController();
|
|
34
|
-
*
|
|
35
|
-
* for await (const event of rlm.queryStream('What is AI?')) {
|
|
36
|
-
* if (event.type === 'token') {
|
|
37
|
-
* process.stdout.write(event.text);
|
|
38
|
-
* } else {
|
|
39
|
-
* console.log('\n\nDone! Quality:', event.answer.qualityScore);
|
|
40
|
-
* }
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @example With Reflection
|
|
45
|
-
* ```typescript
|
|
46
|
-
* const rlm = new RlmController({
|
|
47
|
-
* enableReflection: true,
|
|
48
|
-
* maxReflectionIterations: 2,
|
|
49
|
-
* minQualityScore: 0.8,
|
|
50
|
-
* });
|
|
51
|
-
*
|
|
52
|
-
* const answer = await rlm.query('Complex multi-part question...');
|
|
53
|
-
* // Answer will be iteratively refined until quality >= 0.8
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
import { RlmConfig, RlmAnswer, MemorySpan, StreamToken } from './types';
|
|
57
|
-
import { RuvLLM } from '../engine';
|
|
58
|
-
/**
|
|
59
|
-
* RlmController - Recursive Retrieval Language Model Controller
|
|
60
|
-
*
|
|
61
|
-
* Orchestrates retrieval-augmented generation with recursive sub-query
|
|
62
|
-
* decomposition, memory search, and optional self-reflection.
|
|
63
|
-
*/
|
|
64
|
-
export declare class RlmController {
|
|
65
|
-
private config;
|
|
66
|
-
private cache;
|
|
67
|
-
private engine;
|
|
68
|
-
private memoryIdCounter;
|
|
69
|
-
/**
|
|
70
|
-
* Create a new RLM controller
|
|
71
|
-
*
|
|
72
|
-
* @param config - Configuration options
|
|
73
|
-
* @param engine - Optional RuvLLM engine instance (creates new if not provided)
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* // With default config
|
|
78
|
-
* const rlm = new RlmController();
|
|
79
|
-
*
|
|
80
|
-
* // With custom config
|
|
81
|
-
* const rlm = new RlmController({
|
|
82
|
-
* maxDepth: 5,
|
|
83
|
-
* enableReflection: true,
|
|
84
|
-
* });
|
|
85
|
-
*
|
|
86
|
-
* // With existing engine
|
|
87
|
-
* const engine = new RuvLLM({ learningEnabled: true });
|
|
88
|
-
* const rlm = new RlmController({}, engine);
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
constructor(config?: RlmConfig, engine?: RuvLLM);
|
|
92
|
-
/**
|
|
93
|
-
* Query the RLM with recursive retrieval
|
|
94
|
-
*
|
|
95
|
-
* @param input - The query string
|
|
96
|
-
* @returns Promise resolving to the answer with sources and metadata
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* const answer = await rlm.query('What is the capital of France?');
|
|
101
|
-
* console.log(answer.text); // "The capital of France is Paris..."
|
|
102
|
-
* console.log(answer.confidence); // 0.95
|
|
103
|
-
* console.log(answer.sources); // [{ id: '...', text: '...', similarityScore: 0.92 }]
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
query(input: string): Promise<RlmAnswer>;
|
|
107
|
-
/**
|
|
108
|
-
* Query with streaming response
|
|
109
|
-
*
|
|
110
|
-
* @param input - The query string
|
|
111
|
-
* @yields StreamToken events (either partial tokens or final answer)
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* for await (const event of rlm.queryStream('Explain quantum computing')) {
|
|
116
|
-
* if (event.type === 'token') {
|
|
117
|
-
* // Partial token received
|
|
118
|
-
* process.stdout.write(event.text);
|
|
119
|
-
* } else {
|
|
120
|
-
* // Generation complete
|
|
121
|
-
* console.log('\n\nSources:', event.answer.sources.length);
|
|
122
|
-
* }
|
|
123
|
-
* }
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
queryStream(input: string): AsyncGenerator<StreamToken>;
|
|
127
|
-
/**
|
|
128
|
-
* Add content to memory for retrieval
|
|
129
|
-
*
|
|
130
|
-
* @param text - The text content to store
|
|
131
|
-
* @param metadata - Optional metadata to associate with the memory
|
|
132
|
-
* @returns Promise resolving to the memory span ID
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```typescript
|
|
136
|
-
* const id1 = await rlm.addMemory(
|
|
137
|
-
* 'TypeScript is a typed superset of JavaScript.',
|
|
138
|
-
* { source: 'documentation', category: 'programming' }
|
|
139
|
-
* );
|
|
140
|
-
*
|
|
141
|
-
* const id2 = await rlm.addMemory(
|
|
142
|
-
* 'React is a JavaScript library for building UIs.'
|
|
143
|
-
* );
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
addMemory(text: string, metadata?: Record<string, unknown>): Promise<string>;
|
|
147
|
-
/**
|
|
148
|
-
* Search memory for relevant spans
|
|
149
|
-
*
|
|
150
|
-
* @param query - The search query
|
|
151
|
-
* @param topK - Number of results to return (default: config.retrievalTopK)
|
|
152
|
-
* @returns Promise resolving to array of memory spans
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* const spans = await rlm.searchMemory('JavaScript frameworks', 5);
|
|
157
|
-
* for (const span of spans) {
|
|
158
|
-
* console.log(`[${span.similarityScore.toFixed(2)}] ${span.text}`);
|
|
159
|
-
* }
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
searchMemory(query: string, topK?: number): Promise<MemorySpan[]>;
|
|
163
|
-
/**
|
|
164
|
-
* Clear the response cache
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* rlm.clearCache();
|
|
169
|
-
* console.log('Cache cleared');
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
clearCache(): void;
|
|
173
|
-
/**
|
|
174
|
-
* Get current cache statistics
|
|
175
|
-
*
|
|
176
|
-
* @returns Object with cache size and hit rate info
|
|
177
|
-
*/
|
|
178
|
-
getCacheStats(): {
|
|
179
|
-
size: number;
|
|
180
|
-
entries: number;
|
|
181
|
-
};
|
|
182
|
-
/**
|
|
183
|
-
* Update configuration at runtime
|
|
184
|
-
*
|
|
185
|
-
* @param config - Partial configuration to merge
|
|
186
|
-
*/
|
|
187
|
-
updateConfig(config: Partial<RlmConfig>): void;
|
|
188
|
-
/**
|
|
189
|
-
* Get current configuration
|
|
190
|
-
*/
|
|
191
|
-
getConfig(): Required<RlmConfig>;
|
|
192
|
-
/**
|
|
193
|
-
* Generate sub-queries for complex questions
|
|
194
|
-
*/
|
|
195
|
-
private generateSubQueries;
|
|
196
|
-
/**
|
|
197
|
-
* Decompose a complex query into simpler parts
|
|
198
|
-
*/
|
|
199
|
-
private decomposeQuery;
|
|
200
|
-
/**
|
|
201
|
-
* Build context string from sources and sub-queries
|
|
202
|
-
*/
|
|
203
|
-
private buildContext;
|
|
204
|
-
/**
|
|
205
|
-
* Build the full prompt with context
|
|
206
|
-
*/
|
|
207
|
-
private buildPrompt;
|
|
208
|
-
/**
|
|
209
|
-
* Get generation config based on RLM settings
|
|
210
|
-
*/
|
|
211
|
-
private getGenerationConfig;
|
|
212
|
-
/**
|
|
213
|
-
* Estimate token usage
|
|
214
|
-
*/
|
|
215
|
-
private estimateTokenUsage;
|
|
216
|
-
/**
|
|
217
|
-
* Calculate quality score based on sources and confidence
|
|
218
|
-
*/
|
|
219
|
-
private calculateQualityScore;
|
|
220
|
-
/**
|
|
221
|
-
* Apply self-reflection to improve answer
|
|
222
|
-
*/
|
|
223
|
-
private applyReflection;
|
|
224
|
-
/**
|
|
225
|
-
* Get cached answer if valid
|
|
226
|
-
*/
|
|
227
|
-
private getCached;
|
|
228
|
-
/**
|
|
229
|
-
* Set cache entry
|
|
230
|
-
*/
|
|
231
|
-
private setCache;
|
|
232
|
-
/**
|
|
233
|
-
* Simple hash function for cache keys
|
|
234
|
-
*/
|
|
235
|
-
private hashQuery;
|
|
236
|
-
/**
|
|
237
|
-
* Prune expired cache entries
|
|
238
|
-
*/
|
|
239
|
-
private pruneCache;
|
|
240
|
-
/**
|
|
241
|
-
* Utility delay function for streaming simulation
|
|
242
|
-
*/
|
|
243
|
-
private delay;
|
|
244
|
-
}
|
|
245
|
-
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/rlm/controller.ts"],"names":[],"mappings":"AAAA;;;;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