@hazeljs/rag 0.2.0-beta.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/README.md +379 -0
- package/dist/agentic/agentic-rag.service.d.ts +49 -0
- package/dist/agentic/agentic-rag.service.d.ts.map +1 -0
- package/dist/agentic/agentic-rag.service.js +149 -0
- package/dist/agentic/agentic-rag.service.js.map +1 -0
- package/dist/agentic/decorators/active-learning.decorator.d.ts +19 -0
- package/dist/agentic/decorators/active-learning.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/active-learning.decorator.js +98 -0
- package/dist/agentic/decorators/active-learning.decorator.js.map +1 -0
- package/dist/agentic/decorators/adaptive-retrieval.decorator.d.ts +16 -0
- package/dist/agentic/decorators/adaptive-retrieval.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/adaptive-retrieval.decorator.js +114 -0
- package/dist/agentic/decorators/adaptive-retrieval.decorator.js.map +1 -0
- package/dist/agentic/decorators/cached.decorator.d.ts +18 -0
- package/dist/agentic/decorators/cached.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/cached.decorator.js +93 -0
- package/dist/agentic/decorators/cached.decorator.js.map +1 -0
- package/dist/agentic/decorators/context-aware.decorator.d.ts +16 -0
- package/dist/agentic/decorators/context-aware.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/context-aware.decorator.js +169 -0
- package/dist/agentic/decorators/context-aware.decorator.js.map +1 -0
- package/dist/agentic/decorators/corrective-rag.decorator.d.ts +15 -0
- package/dist/agentic/decorators/corrective-rag.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/corrective-rag.decorator.js +146 -0
- package/dist/agentic/decorators/corrective-rag.decorator.js.map +1 -0
- package/dist/agentic/decorators/hyde.decorator.d.ts +14 -0
- package/dist/agentic/decorators/hyde.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/hyde.decorator.js +90 -0
- package/dist/agentic/decorators/hyde.decorator.js.map +1 -0
- package/dist/agentic/decorators/index.d.ts +16 -0
- package/dist/agentic/decorators/index.d.ts.map +1 -0
- package/dist/agentic/decorators/index.js +32 -0
- package/dist/agentic/decorators/index.js.map +1 -0
- package/dist/agentic/decorators/multi-hop.decorator.d.ts +14 -0
- package/dist/agentic/decorators/multi-hop.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/multi-hop.decorator.js +120 -0
- package/dist/agentic/decorators/multi-hop.decorator.js.map +1 -0
- package/dist/agentic/decorators/query-planner.decorator.d.ts +19 -0
- package/dist/agentic/decorators/query-planner.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/query-planner.decorator.js +227 -0
- package/dist/agentic/decorators/query-planner.decorator.js.map +1 -0
- package/dist/agentic/decorators/query-rewriter.decorator.d.ts +15 -0
- package/dist/agentic/decorators/query-rewriter.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/query-rewriter.decorator.js +140 -0
- package/dist/agentic/decorators/query-rewriter.decorator.js.map +1 -0
- package/dist/agentic/decorators/self-reflective.decorator.d.ts +18 -0
- package/dist/agentic/decorators/self-reflective.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/self-reflective.decorator.js +210 -0
- package/dist/agentic/decorators/self-reflective.decorator.js.map +1 -0
- package/dist/agentic/decorators/source-verification.decorator.d.ts +15 -0
- package/dist/agentic/decorators/source-verification.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/source-verification.decorator.js +121 -0
- package/dist/agentic/decorators/source-verification.decorator.js.map +1 -0
- package/dist/agentic/index.d.ts +9 -0
- package/dist/agentic/index.d.ts.map +1 -0
- package/dist/agentic/index.js +25 -0
- package/dist/agentic/index.js.map +1 -0
- package/dist/agentic/types.d.ts +209 -0
- package/dist/agentic/types.d.ts.map +1 -0
- package/dist/agentic/types.js +7 -0
- package/dist/agentic/types.js.map +1 -0
- package/dist/decorators/embeddable.decorator.d.ts +31 -0
- package/dist/decorators/embeddable.decorator.d.ts.map +1 -0
- package/dist/decorators/embeddable.decorator.js +44 -0
- package/dist/decorators/embeddable.decorator.js.map +1 -0
- package/dist/decorators/rag.decorator.d.ts +58 -0
- package/dist/decorators/rag.decorator.d.ts.map +1 -0
- package/dist/decorators/rag.decorator.js +78 -0
- package/dist/decorators/rag.decorator.js.map +1 -0
- package/dist/decorators/semantic-search.decorator.d.ts +69 -0
- package/dist/decorators/semantic-search.decorator.d.ts.map +1 -0
- package/dist/decorators/semantic-search.decorator.js +116 -0
- package/dist/decorators/semantic-search.decorator.js.map +1 -0
- package/dist/embeddings/cohere-embeddings.d.ts +33 -0
- package/dist/embeddings/cohere-embeddings.d.ts.map +1 -0
- package/dist/embeddings/cohere-embeddings.js +91 -0
- package/dist/embeddings/cohere-embeddings.js.map +1 -0
- package/dist/embeddings/openai-embeddings.d.ts +21 -0
- package/dist/embeddings/openai-embeddings.d.ts.map +1 -0
- package/dist/embeddings/openai-embeddings.js +53 -0
- package/dist/embeddings/openai-embeddings.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/index.d.ts +11 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +31 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/memory-manager.d.ts +96 -0
- package/dist/memory/memory-manager.d.ts.map +1 -0
- package/dist/memory/memory-manager.js +369 -0
- package/dist/memory/memory-manager.js.map +1 -0
- package/dist/memory/memory-store.interface.d.ts +73 -0
- package/dist/memory/memory-store.interface.d.ts.map +1 -0
- package/dist/memory/memory-store.interface.js +6 -0
- package/dist/memory/memory-store.interface.js.map +1 -0
- package/dist/memory/stores/buffer-memory.d.ts +47 -0
- package/dist/memory/stores/buffer-memory.d.ts.map +1 -0
- package/dist/memory/stores/buffer-memory.js +280 -0
- package/dist/memory/stores/buffer-memory.js.map +1 -0
- package/dist/memory/stores/hybrid-memory.d.ts +49 -0
- package/dist/memory/stores/hybrid-memory.d.ts.map +1 -0
- package/dist/memory/stores/hybrid-memory.js +194 -0
- package/dist/memory/stores/hybrid-memory.js.map +1 -0
- package/dist/memory/stores/vector-memory.d.ts +48 -0
- package/dist/memory/stores/vector-memory.d.ts.map +1 -0
- package/dist/memory/stores/vector-memory.js +312 -0
- package/dist/memory/stores/vector-memory.js.map +1 -0
- package/dist/memory/types.d.ts +119 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +18 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/rag-pipeline-with-memory.d.ts +68 -0
- package/dist/rag-pipeline-with-memory.d.ts.map +1 -0
- package/dist/rag-pipeline-with-memory.js +186 -0
- package/dist/rag-pipeline-with-memory.js.map +1 -0
- package/dist/rag-pipeline.d.ts +59 -0
- package/dist/rag-pipeline.d.ts.map +1 -0
- package/dist/rag-pipeline.js +181 -0
- package/dist/rag-pipeline.js.map +1 -0
- package/dist/rag.module.d.ts +26 -0
- package/dist/rag.module.d.ts.map +1 -0
- package/dist/rag.module.js +40 -0
- package/dist/rag.module.js.map +1 -0
- package/dist/rag.service.d.ts +95 -0
- package/dist/rag.service.d.ts.map +1 -0
- package/dist/rag.service.js +174 -0
- package/dist/rag.service.js.map +1 -0
- package/dist/retrieval/bm25.d.ts +57 -0
- package/dist/retrieval/bm25.d.ts.map +1 -0
- package/dist/retrieval/bm25.js +106 -0
- package/dist/retrieval/bm25.js.map +1 -0
- package/dist/retrieval/hybrid-search.d.ts +48 -0
- package/dist/retrieval/hybrid-search.d.ts.map +1 -0
- package/dist/retrieval/hybrid-search.js +123 -0
- package/dist/retrieval/hybrid-search.js.map +1 -0
- package/dist/retrieval/multi-query.d.ts +38 -0
- package/dist/retrieval/multi-query.d.ts.map +1 -0
- package/dist/retrieval/multi-query.js +135 -0
- package/dist/retrieval/multi-query.js.map +1 -0
- package/dist/text-splitters/recursive-text-splitter.d.ts +21 -0
- package/dist/text-splitters/recursive-text-splitter.d.ts.map +1 -0
- package/dist/text-splitters/recursive-text-splitter.js +95 -0
- package/dist/text-splitters/recursive-text-splitter.js.map +1 -0
- package/dist/types/index.d.ts +144 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/similarity.d.ts +16 -0
- package/dist/utils/similarity.d.ts.map +1 -0
- package/dist/utils/similarity.js +58 -0
- package/dist/utils/similarity.js.map +1 -0
- package/dist/vector-stores/chroma.store.d.ts +42 -0
- package/dist/vector-stores/chroma.store.d.ts.map +1 -0
- package/dist/vector-stores/chroma.store.js +242 -0
- package/dist/vector-stores/chroma.store.js.map +1 -0
- package/dist/vector-stores/memory-vector-store.d.ts +20 -0
- package/dist/vector-stores/memory-vector-store.d.ts.map +1 -0
- package/dist/vector-stores/memory-vector-store.js +94 -0
- package/dist/vector-stores/memory-vector-store.js.map +1 -0
- package/dist/vector-stores/pinecone.store.d.ts +34 -0
- package/dist/vector-stores/pinecone.store.d.ts.map +1 -0
- package/dist/vector-stores/pinecone.store.js +146 -0
- package/dist/vector-stores/pinecone.store.js.map +1 -0
- package/dist/vector-stores/qdrant.store.d.ts +31 -0
- package/dist/vector-stores/qdrant.store.d.ts.map +1 -0
- package/dist/vector-stores/qdrant.store.js +173 -0
- package/dist/vector-stores/qdrant.store.js.map +1 -0
- package/dist/vector-stores/weaviate.store.d.ts +37 -0
- package/dist/vector-stores/weaviate.store.d.ts.map +1 -0
- package/dist/vector-stores/weaviate.store.js +226 -0
- package/dist/vector-stores/weaviate.store.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query Planner Decorator
|
|
4
|
+
* Automatically decomposes complex queries into sub-queries
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.QueryPlanner = QueryPlanner;
|
|
8
|
+
exports.getQueryPlan = getQueryPlan;
|
|
9
|
+
require("reflect-metadata");
|
|
10
|
+
const QUERY_PLANNER_METADATA_KEY = Symbol('queryPlanner');
|
|
11
|
+
function QueryPlanner(config = {}) {
|
|
12
|
+
return function (target, propertyKey, descriptor) {
|
|
13
|
+
const originalMethod = descriptor.value;
|
|
14
|
+
descriptor.value = async function (...args) {
|
|
15
|
+
const query = args[0];
|
|
16
|
+
if (!config.decompose) {
|
|
17
|
+
return originalMethod.apply(this, args);
|
|
18
|
+
}
|
|
19
|
+
// Decompose query into sub-queries
|
|
20
|
+
const plan = await decomposeQuery(query, config);
|
|
21
|
+
// Store plan in metadata
|
|
22
|
+
Reflect.defineMetadata(QUERY_PLANNER_METADATA_KEY, plan, target, propertyKey);
|
|
23
|
+
// Execute based on strategy
|
|
24
|
+
if (plan.strategy === 'parallel' && config.parallel) {
|
|
25
|
+
return executeParallel.call(this, plan, originalMethod, args);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return executeSequential.call(this, plan, originalMethod, args);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return descriptor;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Decompose query into sub-queries
|
|
36
|
+
*/
|
|
37
|
+
async function decomposeQuery(query, config) {
|
|
38
|
+
// Check if query is complex enough to decompose
|
|
39
|
+
const complexity = estimateComplexity(query);
|
|
40
|
+
if (complexity < 3) {
|
|
41
|
+
return {
|
|
42
|
+
originalQuery: query,
|
|
43
|
+
subQueries: [
|
|
44
|
+
{
|
|
45
|
+
id: '1',
|
|
46
|
+
query,
|
|
47
|
+
type: 'factual',
|
|
48
|
+
dependencies: [],
|
|
49
|
+
priority: 1,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
strategy: 'sequential',
|
|
53
|
+
estimatedComplexity: complexity,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Use LLM to decompose if available
|
|
57
|
+
if (config.llmProvider) {
|
|
58
|
+
return decomposeWithLLM(query, config);
|
|
59
|
+
}
|
|
60
|
+
// Fallback to rule-based decomposition
|
|
61
|
+
return decomposeRuleBased(query, config);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* LLM-based query decomposition
|
|
65
|
+
*/
|
|
66
|
+
async function decomposeWithLLM(query, config) {
|
|
67
|
+
const prompt = `Decompose the following complex query into simpler sub-queries.
|
|
68
|
+
Each sub-query should be independent and focused on a specific aspect.
|
|
69
|
+
|
|
70
|
+
Query: ${query}
|
|
71
|
+
|
|
72
|
+
Provide the decomposition in the following JSON format:
|
|
73
|
+
{
|
|
74
|
+
"subQueries": [
|
|
75
|
+
{
|
|
76
|
+
"id": "1",
|
|
77
|
+
"query": "sub-query text",
|
|
78
|
+
"type": "factual|analytical|comparative|temporal",
|
|
79
|
+
"dependencies": [],
|
|
80
|
+
"priority": 1
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"strategy": "sequential|parallel"
|
|
84
|
+
}`;
|
|
85
|
+
try {
|
|
86
|
+
const result = await config.llmProvider.generateStructured(prompt, {});
|
|
87
|
+
return {
|
|
88
|
+
originalQuery: query,
|
|
89
|
+
subQueries: result.subQueries.slice(0, config.maxSubQueries || 5),
|
|
90
|
+
strategy: result.strategy,
|
|
91
|
+
estimatedComplexity: result.subQueries.length,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return decomposeRuleBased(query, config);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Rule-based query decomposition
|
|
100
|
+
*/
|
|
101
|
+
function decomposeRuleBased(query, config) {
|
|
102
|
+
const subQueries = [];
|
|
103
|
+
// Split by conjunctions
|
|
104
|
+
const parts = query.split(/\band\b|\bor\b|\bthen\b/i);
|
|
105
|
+
parts.forEach((part, index) => {
|
|
106
|
+
const trimmed = part.trim();
|
|
107
|
+
if (trimmed.length > 10) {
|
|
108
|
+
subQueries.push({
|
|
109
|
+
id: String(index + 1),
|
|
110
|
+
query: trimmed,
|
|
111
|
+
type: detectQueryType(trimmed),
|
|
112
|
+
dependencies: index > 0 ? [String(index)] : [],
|
|
113
|
+
priority: index + 1,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
if (subQueries.length === 0) {
|
|
118
|
+
subQueries.push({
|
|
119
|
+
id: '1',
|
|
120
|
+
query,
|
|
121
|
+
type: 'factual',
|
|
122
|
+
dependencies: [],
|
|
123
|
+
priority: 1,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
originalQuery: query,
|
|
128
|
+
subQueries: subQueries.slice(0, config.maxSubQueries || 5),
|
|
129
|
+
strategy: subQueries.length > 1 ? 'parallel' : 'sequential',
|
|
130
|
+
estimatedComplexity: subQueries.length,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Detect query type
|
|
135
|
+
*/
|
|
136
|
+
function detectQueryType(query) {
|
|
137
|
+
const lowerQuery = query.toLowerCase();
|
|
138
|
+
if (lowerQuery.includes('compare') || lowerQuery.includes('difference')) {
|
|
139
|
+
return 'comparative';
|
|
140
|
+
}
|
|
141
|
+
if (lowerQuery.includes('when') || lowerQuery.includes('timeline')) {
|
|
142
|
+
return 'temporal';
|
|
143
|
+
}
|
|
144
|
+
if (lowerQuery.includes('why') || lowerQuery.includes('how') || lowerQuery.includes('analyze')) {
|
|
145
|
+
return 'analytical';
|
|
146
|
+
}
|
|
147
|
+
return 'factual';
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Estimate query complexity
|
|
151
|
+
*/
|
|
152
|
+
function estimateComplexity(query) {
|
|
153
|
+
let score = 1;
|
|
154
|
+
// Length factor
|
|
155
|
+
if (query.length > 100)
|
|
156
|
+
score += 1;
|
|
157
|
+
if (query.length > 200)
|
|
158
|
+
score += 1;
|
|
159
|
+
// Multiple questions
|
|
160
|
+
const questionMarks = (query.match(/\?/g) || []).length;
|
|
161
|
+
score += questionMarks;
|
|
162
|
+
// Conjunctions
|
|
163
|
+
const conjunctions = (query.match(/\band\b|\bor\b|\bthen\b/gi) || []).length;
|
|
164
|
+
score += conjunctions;
|
|
165
|
+
// Complex words
|
|
166
|
+
const complexWords = ['compare', 'analyze', 'evaluate', 'synthesize'];
|
|
167
|
+
complexWords.forEach((word) => {
|
|
168
|
+
if (query.toLowerCase().includes(word))
|
|
169
|
+
score += 1;
|
|
170
|
+
});
|
|
171
|
+
return Math.min(score, 10);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Execute sub-queries in parallel
|
|
175
|
+
*/
|
|
176
|
+
async function executeParallel(plan,
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
178
|
+
originalMethod, args) {
|
|
179
|
+
const results = await Promise.all(plan.subQueries.map((subQuery) => originalMethod.apply(this, [subQuery.query, ...args.slice(1)])));
|
|
180
|
+
// Merge results
|
|
181
|
+
return mergeResults(results, plan);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Execute sub-queries sequentially
|
|
185
|
+
*/
|
|
186
|
+
async function executeSequential(plan,
|
|
187
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
188
|
+
originalMethod, args) {
|
|
189
|
+
const results = [];
|
|
190
|
+
for (const subQuery of plan.subQueries) {
|
|
191
|
+
const result = await originalMethod.apply(this, [subQuery.query, ...args.slice(1)]);
|
|
192
|
+
results.push(result);
|
|
193
|
+
}
|
|
194
|
+
return mergeResults(results, plan);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Merge results from sub-queries
|
|
198
|
+
*/
|
|
199
|
+
function mergeResults(results, _plan) {
|
|
200
|
+
if (!Array.isArray(results[0])) {
|
|
201
|
+
return results;
|
|
202
|
+
}
|
|
203
|
+
// Flatten and deduplicate search results
|
|
204
|
+
const allResults = results.flat();
|
|
205
|
+
const seen = new Set();
|
|
206
|
+
const merged = [];
|
|
207
|
+
for (const result of allResults) {
|
|
208
|
+
if (typeof result === 'object' &&
|
|
209
|
+
result !== null &&
|
|
210
|
+
'id' in result &&
|
|
211
|
+
typeof result.id === 'string') {
|
|
212
|
+
const id = result.id;
|
|
213
|
+
if (!seen.has(id)) {
|
|
214
|
+
seen.add(id);
|
|
215
|
+
merged.push(result);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return merged;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get query plan metadata
|
|
223
|
+
*/
|
|
224
|
+
function getQueryPlan(target, propertyKey) {
|
|
225
|
+
return Reflect.getMetadata(QUERY_PLANNER_METADATA_KEY, target, propertyKey);
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=query-planner.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-planner.decorator.js","sourceRoot":"","sources":["../../../src/agentic/decorators/query-planner.decorator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAeH,oCA2BC;AA2OD,oCAEC;AArRD,4BAA0B;AAW1B,MAAM,0BAA0B,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAE1D,SAAgB,YAAY,CAAC,SAA6B,EAAE;IAC1D,OAAO,UAAU,MAAc,EAAE,WAA4B,EAAE,UAA8B;QAC3F,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAe;YACnD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAW,CAAC;YAEhC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;gBACtB,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC1C,CAAC;YAED,mCAAmC;YACnC,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAEjD,yBAAyB;YACzB,OAAO,CAAC,cAAc,CAAC,0BAA0B,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;YA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;AAC9E,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Rewriter Decorator
|
|
3
|
+
* Rewrites and expands queries for better retrieval
|
|
4
|
+
*/
|
|
5
|
+
import 'reflect-metadata';
|
|
6
|
+
import { AgenticLLMProvider } from '../types';
|
|
7
|
+
export interface QueryRewriterConfig {
|
|
8
|
+
techniques?: ('expansion' | 'clarification' | 'synonym' | 'decomposition')[];
|
|
9
|
+
llmBased?: boolean;
|
|
10
|
+
llmProvider?: AgenticLLMProvider;
|
|
11
|
+
maxVariations?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function QueryRewriter(config?: QueryRewriterConfig): MethodDecorator;
|
|
14
|
+
export declare function getQueryVariations(target: object, propertyKey: string | symbol): string[];
|
|
15
|
+
//# sourceMappingURL=query-rewriter.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-rewriter.decorator.d.ts","sourceRoot":"","sources":["../../../src/agentic/decorators/query-rewriter.decorator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,CAAC,WAAW,GAAG,eAAe,GAAG,SAAS,GAAG,eAAe,CAAC,EAAE,CAAC;IAC7E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAID,wBAAgB,aAAa,CAAC,MAAM,GAAE,mBAAwB,GAAG,eAAe,CAqC/E;AA+HD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAEzF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query Rewriter Decorator
|
|
4
|
+
* Rewrites and expands queries for better retrieval
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.QueryRewriter = QueryRewriter;
|
|
8
|
+
exports.getQueryVariations = getQueryVariations;
|
|
9
|
+
require("reflect-metadata");
|
|
10
|
+
const REWRITER_METADATA_KEY = Symbol('queryRewriter');
|
|
11
|
+
function QueryRewriter(config = {}) {
|
|
12
|
+
return function (target, propertyKey, descriptor) {
|
|
13
|
+
const originalMethod = descriptor.value;
|
|
14
|
+
descriptor.value = async function (...args) {
|
|
15
|
+
const query = args[0];
|
|
16
|
+
// Generate query variations
|
|
17
|
+
const variations = await generateQueryVariations(query, config);
|
|
18
|
+
// Execute search with all variations
|
|
19
|
+
const allResults = [];
|
|
20
|
+
const seenIds = new Set();
|
|
21
|
+
for (const variation of variations) {
|
|
22
|
+
const results = await originalMethod.apply(this, [variation, ...args.slice(1)]);
|
|
23
|
+
if (Array.isArray(results)) {
|
|
24
|
+
for (const result of results) {
|
|
25
|
+
if (result.id && !seenIds.has(result.id)) {
|
|
26
|
+
seenIds.add(result.id);
|
|
27
|
+
allResults.push(result);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Re-rank by frequency across variations
|
|
33
|
+
const ranked = rerankByFrequency(allResults, variations.length);
|
|
34
|
+
Reflect.defineMetadata(REWRITER_METADATA_KEY, variations, target, propertyKey);
|
|
35
|
+
return ranked;
|
|
36
|
+
};
|
|
37
|
+
return descriptor;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async function generateQueryVariations(query, config) {
|
|
41
|
+
const variations = [query]; // Always include original
|
|
42
|
+
const techniques = config.techniques || ['expansion', 'synonym'];
|
|
43
|
+
const maxVariations = config.maxVariations || 3;
|
|
44
|
+
if (config.llmBased && config.llmProvider) {
|
|
45
|
+
return generateWithLLM(query, techniques, config.llmProvider, maxVariations);
|
|
46
|
+
}
|
|
47
|
+
// Rule-based variations
|
|
48
|
+
for (const technique of techniques) {
|
|
49
|
+
switch (technique) {
|
|
50
|
+
case 'expansion':
|
|
51
|
+
variations.push(...expandQuery(query));
|
|
52
|
+
break;
|
|
53
|
+
case 'synonym':
|
|
54
|
+
variations.push(...addSynonyms(query));
|
|
55
|
+
break;
|
|
56
|
+
case 'clarification':
|
|
57
|
+
variations.push(...clarifyQuery(query));
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [...new Set(variations)].slice(0, maxVariations + 1);
|
|
62
|
+
}
|
|
63
|
+
async function generateWithLLM(query, techniques, llmProvider, maxVariations) {
|
|
64
|
+
const prompt = `Generate ${maxVariations} variations of this query using these techniques: ${techniques.join(', ')}
|
|
65
|
+
|
|
66
|
+
Original Query: ${query}
|
|
67
|
+
|
|
68
|
+
Generate ${maxVariations} query variations (one per line):`;
|
|
69
|
+
try {
|
|
70
|
+
const response = await llmProvider.generate(prompt, { temperature: 0.7 });
|
|
71
|
+
const variations = response
|
|
72
|
+
.split('\n')
|
|
73
|
+
.map((line) => line.replace(/^\d+\.\s*/, '').trim())
|
|
74
|
+
.filter((line) => line.length > 5)
|
|
75
|
+
.slice(0, maxVariations);
|
|
76
|
+
return [query, ...variations];
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return [query];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function expandQuery(query) {
|
|
83
|
+
const expansions = [];
|
|
84
|
+
// Add question words if not present
|
|
85
|
+
if (!query.match(/^(what|who|where|when|why|how)/i)) {
|
|
86
|
+
expansions.push(`What is ${query}?`);
|
|
87
|
+
expansions.push(`How does ${query} work?`);
|
|
88
|
+
}
|
|
89
|
+
// Add context
|
|
90
|
+
expansions.push(`${query} explanation`);
|
|
91
|
+
expansions.push(`${query} details`);
|
|
92
|
+
return expansions;
|
|
93
|
+
}
|
|
94
|
+
function addSynonyms(query) {
|
|
95
|
+
const synonymMap = {
|
|
96
|
+
find: ['search', 'locate', 'discover'],
|
|
97
|
+
show: ['display', 'present', 'demonstrate'],
|
|
98
|
+
explain: ['describe', 'clarify', 'elaborate'],
|
|
99
|
+
compare: ['contrast', 'differentiate', 'analyze'],
|
|
100
|
+
};
|
|
101
|
+
const variations = [];
|
|
102
|
+
const words = query.split(/\s+/);
|
|
103
|
+
words.forEach((word, index) => {
|
|
104
|
+
const lowerWord = word.toLowerCase();
|
|
105
|
+
if (synonymMap[lowerWord]) {
|
|
106
|
+
synonymMap[lowerWord].forEach((synonym) => {
|
|
107
|
+
const newWords = [...words];
|
|
108
|
+
newWords[index] = synonym;
|
|
109
|
+
variations.push(newWords.join(' '));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return variations;
|
|
114
|
+
}
|
|
115
|
+
function clarifyQuery(query) {
|
|
116
|
+
const clarifications = [];
|
|
117
|
+
// Add specificity
|
|
118
|
+
if (query.length < 50) {
|
|
119
|
+
clarifications.push(`${query} with examples`);
|
|
120
|
+
clarifications.push(`${query} in detail`);
|
|
121
|
+
}
|
|
122
|
+
return clarifications;
|
|
123
|
+
}
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
+
function rerankByFrequency(results, variationCount) {
|
|
126
|
+
const frequency = new Map();
|
|
127
|
+
results.forEach((result) => {
|
|
128
|
+
frequency.set(result.id, (frequency.get(result.id) || 0) + 1);
|
|
129
|
+
});
|
|
130
|
+
return results
|
|
131
|
+
.map((result) => ({
|
|
132
|
+
...result,
|
|
133
|
+
score: (result.score || 0) * (1 + (frequency.get(result.id) || 0) / variationCount),
|
|
134
|
+
}))
|
|
135
|
+
.sort((a, b) => (b.score || 0) - (a.score || 0));
|
|
136
|
+
}
|
|
137
|
+
function getQueryVariations(target, propertyKey) {
|
|
138
|
+
return Reflect.getMetadata(REWRITER_METADATA_KEY, target, propertyKey) || [];
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=query-rewriter.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-rewriter.decorator.js","sourceRoot":"","sources":["../../../src/agentic/decorators/query-rewriter.decorator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAcH,sCAqCC;AA+HD,gDAEC;AAlLD,4BAA0B;AAU1B,MAAM,qBAAqB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAEtD,SAAgB,aAAa,CAAC,SAA8B,EAAE;IAC5D,OAAO,UAAU,MAAc,EAAE,WAA4B,EAAE,UAA8B;QAC3F,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAe;YACnD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAW,CAAC;YAEhC,4BAA4B;YAC5B,MAAM,UAAU,GAAG,MAAM,uBAAuB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAEhE,qCAAqC;YACrC,MAAM,UAAU,GAAG,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;YAElC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACnC,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAEhF,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC3B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;wBAC7B,IAAI,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;4BACzC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;4BACvB,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CA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ionResult, AgenticLLMProvider } from '../types';
|
|
7
|
+
export interface SelfReflectiveConfig {
|
|
8
|
+
maxIterations?: number;
|
|
9
|
+
qualityThreshold?: number;
|
|
10
|
+
llmProvider?: AgenticLLMProvider;
|
|
11
|
+
enableAutoImprovement?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function SelfReflective(config?: SelfReflectiveConfig): MethodDecorator;
|
|
14
|
+
/**
|
|
15
|
+
* Get reflection metadata
|
|
16
|
+
*/
|
|
17
|
+
export declare function getReflections(target: object, propertyKey: string | symbol): ReflectionResult[];
|
|
18
|
+
//# sourceMappingURL=self-reflective.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-reflective.decorator.d.ts","sourceRoot":"","sources":["../../../src/agentic/decorators/self-reflective.decorator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAqB,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnF,MAAM,WAAW,oBAAoB;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAID,wBAAgB,cAAc,CAAC,MAAM,GAAE,oBAAyB,GAAG,eAAe,CA8DjF;AAqLD;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB,EAAE,CAE/F"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Self-Reflective Decorator
|
|
4
|
+
* Evaluates and iteratively improves retrieval results
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SelfReflective = SelfReflective;
|
|
8
|
+
exports.getReflections = getReflections;
|
|
9
|
+
require("reflect-metadata");
|
|
10
|
+
const REFLECTION_METADATA_KEY = Symbol('reflection');
|
|
11
|
+
function SelfReflective(config = {}) {
|
|
12
|
+
return function (target, propertyKey, descriptor) {
|
|
13
|
+
const originalMethod = descriptor.value;
|
|
14
|
+
descriptor.value = async function (...args) {
|
|
15
|
+
const maxIterations = config.maxIterations || 3;
|
|
16
|
+
const threshold = config.qualityThreshold || 0.8;
|
|
17
|
+
let iteration = 0;
|
|
18
|
+
let currentResult = await originalMethod.apply(this, args);
|
|
19
|
+
let bestResult = currentResult;
|
|
20
|
+
let bestQuality = 0;
|
|
21
|
+
const reflections = [];
|
|
22
|
+
while (iteration < maxIterations) {
|
|
23
|
+
iteration++;
|
|
24
|
+
// Assess quality
|
|
25
|
+
const query = args[0];
|
|
26
|
+
const quality = await assessQuality(currentResult, query, config);
|
|
27
|
+
reflections.push({
|
|
28
|
+
originalResponse: JSON.stringify(currentResult),
|
|
29
|
+
quality,
|
|
30
|
+
improvements: quality.issues,
|
|
31
|
+
iterations: iteration,
|
|
32
|
+
});
|
|
33
|
+
// Track best result
|
|
34
|
+
if (quality.score > bestQuality) {
|
|
35
|
+
bestQuality = quality.score;
|
|
36
|
+
bestResult = currentResult;
|
|
37
|
+
}
|
|
38
|
+
// Check if quality threshold met
|
|
39
|
+
if (quality.score >= threshold) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
// Attempt improvement
|
|
43
|
+
if (config.enableAutoImprovement && config.llmProvider) {
|
|
44
|
+
const improved = await improveResults(currentResult, quality, query, config);
|
|
45
|
+
if (improved) {
|
|
46
|
+
currentResult = improved;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Store reflection metadata
|
|
57
|
+
Reflect.defineMetadata(REFLECTION_METADATA_KEY, reflections, target, propertyKey);
|
|
58
|
+
return bestResult;
|
|
59
|
+
};
|
|
60
|
+
return descriptor;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Assess quality of results
|
|
65
|
+
*/
|
|
66
|
+
async function assessQuality(
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
+
results, query, config) {
|
|
69
|
+
if (config.llmProvider) {
|
|
70
|
+
return assessQualityWithLLM(results, query, config);
|
|
71
|
+
}
|
|
72
|
+
return assessQualityHeuristic(results, query);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* LLM-based quality assessment
|
|
76
|
+
*/
|
|
77
|
+
async function assessQualityWithLLM(
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
results, query, config) {
|
|
80
|
+
const resultsStr = JSON.stringify(results, null, 2);
|
|
81
|
+
const prompt = `Evaluate the quality of these search results for the given query.
|
|
82
|
+
|
|
83
|
+
Query: ${query}
|
|
84
|
+
|
|
85
|
+
Results: ${resultsStr.slice(0, 2000)}
|
|
86
|
+
|
|
87
|
+
Assess the following aspects (0-1 scale):
|
|
88
|
+
1. Relevance: How relevant are the results to the query?
|
|
89
|
+
2. Completeness: Do the results fully answer the query?
|
|
90
|
+
3. Accuracy: Are the results factually accurate?
|
|
91
|
+
4. Clarity: Are the results clear and well-structured?
|
|
92
|
+
|
|
93
|
+
Provide assessment in JSON format:
|
|
94
|
+
{
|
|
95
|
+
"relevance": 0.0-1.0,
|
|
96
|
+
"completeness": 0.0-1.0,
|
|
97
|
+
"accuracy": 0.0-1.0,
|
|
98
|
+
"clarity": 0.0-1.0,
|
|
99
|
+
"issues": ["issue1", "issue2"]
|
|
100
|
+
}`;
|
|
101
|
+
try {
|
|
102
|
+
const assessment = await config.llmProvider.generateStructured(prompt, {});
|
|
103
|
+
const score = (assessment.relevance + assessment.completeness + assessment.accuracy + assessment.clarity) /
|
|
104
|
+
4;
|
|
105
|
+
return {
|
|
106
|
+
score,
|
|
107
|
+
...assessment,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return assessQualityHeuristic(results, query);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Heuristic-based quality assessment
|
|
116
|
+
*/
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
+
function assessQualityHeuristic(results, query) {
|
|
119
|
+
const issues = [];
|
|
120
|
+
let relevance = 0.5;
|
|
121
|
+
let completeness = 0.5;
|
|
122
|
+
const accuracy = 0.8;
|
|
123
|
+
let clarity = 0.7;
|
|
124
|
+
// Check if results exist
|
|
125
|
+
if (!results || (Array.isArray(results) && results.length === 0)) {
|
|
126
|
+
issues.push('No results returned');
|
|
127
|
+
relevance = 0;
|
|
128
|
+
completeness = 0;
|
|
129
|
+
return { score: 0, relevance, completeness, accuracy, clarity, issues };
|
|
130
|
+
}
|
|
131
|
+
// Check result count
|
|
132
|
+
const resultCount = Array.isArray(results) ? results.length : 1;
|
|
133
|
+
if (resultCount < 3) {
|
|
134
|
+
issues.push('Few results returned');
|
|
135
|
+
completeness = 0.5;
|
|
136
|
+
}
|
|
137
|
+
else if (resultCount >= 5) {
|
|
138
|
+
completeness = 0.9;
|
|
139
|
+
}
|
|
140
|
+
// Check for query terms in results
|
|
141
|
+
const queryTerms = query.toLowerCase().split(/\s+/);
|
|
142
|
+
let matchCount = 0;
|
|
143
|
+
if (Array.isArray(results)) {
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
|
+
results.forEach((result) => {
|
|
146
|
+
const content = (result.content || '').toLowerCase();
|
|
147
|
+
queryTerms.forEach((term) => {
|
|
148
|
+
if (content.includes(term))
|
|
149
|
+
matchCount++;
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
relevance = Math.min(matchCount / (queryTerms.length * resultCount), 1);
|
|
153
|
+
}
|
|
154
|
+
if (relevance < 0.3) {
|
|
155
|
+
issues.push('Low relevance to query');
|
|
156
|
+
}
|
|
157
|
+
// Check for diversity
|
|
158
|
+
if (Array.isArray(results) && results.length > 1) {
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
160
|
+
const uniqueContent = new Set(
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
+
results.map((r) => r.content?.slice(0, 100)));
|
|
163
|
+
if (uniqueContent.size < results.length * 0.7) {
|
|
164
|
+
issues.push('Low diversity in results');
|
|
165
|
+
clarity = 0.6;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const score = (relevance + completeness + accuracy + clarity) / 4;
|
|
169
|
+
return { score, relevance, completeness, accuracy, clarity, issues };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Improve results based on quality assessment
|
|
173
|
+
*/
|
|
174
|
+
async function improveResults(
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
176
|
+
results, quality, query, config
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
+
) {
|
|
179
|
+
if (!config.llmProvider) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const prompt = `The following search results have quality issues. Suggest an improved query or retrieval strategy.
|
|
183
|
+
|
|
184
|
+
Original Query: ${query}
|
|
185
|
+
Quality Issues: ${quality.issues.join(', ')}
|
|
186
|
+
Current Results: ${JSON.stringify(results, null, 2).slice(0, 1000)}
|
|
187
|
+
|
|
188
|
+
Suggest improvements in JSON format:
|
|
189
|
+
{
|
|
190
|
+
"improvedQuery": "better query",
|
|
191
|
+
"strategy": "similarity|hybrid|mmr",
|
|
192
|
+
"reasoning": "why this would be better"
|
|
193
|
+
}`;
|
|
194
|
+
try {
|
|
195
|
+
await config.llmProvider.generateStructured(prompt, {});
|
|
196
|
+
// Return null to indicate we should re-query with improvements
|
|
197
|
+
// The calling code would need to handle this
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get reflection metadata
|
|
206
|
+
*/
|
|
207
|
+
function getReflections(target, propertyKey) {
|
|
208
|
+
return Reflect.getMetadata(REFLECTION_METADATA_KEY, target, propertyKey) || [];
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=self-reflective.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-reflective.decorator.js","sourceRoot":"","sources":["../../../src/agentic/decorators/self-reflective.decorator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAcH,wCA8DC;AAwLD,wCAEC;AApQD,4BAA0B;AAU1B,MAAM,uBAAuB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAErD,SAAgB,cAAc,CAAC,SAA+B,EAAE;IAC9D,OAAO,UAAU,MAAc,EAAE,WAA4B,EAAE,UAA8B;QAC3F,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAe;YACnD,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,CAAC,CAAC;YAChD,MAAM,SAAS,GAAG,MAAM,CAAC,gBAAgB,IAAI,GAAG,CAAC;YAEjD,IAAI,SAAS,GAAG,CAAC,CAAC;YAClB,IAAI,aAAa,GAAG,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC3D,IAAI,UAAU,GAAG,aAAa,CAAC;YAC/B,IAAI,WAAW,GAAG,CAAC,CAAC;YAEpB,MAAM,WAAW,GAAuB,EAAE,CAAC;YAE3C,OAAO,SAAS,GAAG,aAAa,EAAE,CAAC;gBACjC,SAAS,EAAE,CAAC;gBAEZ,iBAAiB;gBACjB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAW,CAAC;gBA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AAC,CAAC,EAAE,IAAI,CAAC;;;;;;;EAOhE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAIxC,MAAM,EAAE,EAAE,CAAC,CAAC;QAEf,+DAA+D;QAC/D,6CAA6C;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,WAA4B;IACzE,OAAO,OAAO,CAAC,WAAW,CAAC,uBAAuB,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source Verification Decorator
|
|
3
|
+
* Verifies source quality and generates citations
|
|
4
|
+
*/
|
|
5
|
+
import 'reflect-metadata';
|
|
6
|
+
import { VerifiedResponse } from '../types';
|
|
7
|
+
export interface SourceVerificationConfig {
|
|
8
|
+
checkFreshness?: boolean;
|
|
9
|
+
verifyAuthority?: boolean;
|
|
10
|
+
requireCitations?: boolean;
|
|
11
|
+
freshnessThresholdDays?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function SourceVerification(config?: SourceVerificationConfig): MethodDecorator;
|
|
14
|
+
export declare function getVerifiedResponse(target: object, propertyKey: string | symbol): VerifiedResponse | undefined;
|
|
15
|
+
//# sourceMappingURL=source-verification.decorator.d.ts.map
|