@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
package/README.md
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# @hazeljs/rag
|
|
2
|
+
|
|
3
|
+
**Retrieval-Augmented Generation (RAG) and Vector Search for HazelJS**
|
|
4
|
+
|
|
5
|
+
Build powerful AI applications with semantic search, document retrieval, and LLM-augmented responses.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 🔍 **Vector Search** - Semantic similarity search using embeddings
|
|
10
|
+
- 📚 **Document Management** - Load, split, and index documents
|
|
11
|
+
- 🤖 **RAG Pipeline** - Complete retrieval-augmented generation workflow
|
|
12
|
+
- 🎯 **Multiple Strategies** - Similarity, MMR (Maximal Marginal Relevance), Hybrid search
|
|
13
|
+
- 🔌 **Pluggable Backends** - Support for Pinecone, Weaviate, Qdrant, ChromaDB, and in-memory
|
|
14
|
+
- 🌐 **Multiple Embedding Providers** - OpenAI, Cohere, HuggingFace
|
|
15
|
+
- ✂️ **Smart Text Splitting** - Recursive text splitter with overlap
|
|
16
|
+
- 📊 **Metadata Filtering** - Filter results by custom metadata
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @hazeljs/rag
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Optional Peer Dependencies
|
|
25
|
+
|
|
26
|
+
Install the vector store and embedding provider you want to use:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# OpenAI Embeddings
|
|
30
|
+
npm install openai
|
|
31
|
+
|
|
32
|
+
# Vector Stores (choose one or more)
|
|
33
|
+
npm install @pinecone-database/pinecone # Pinecone
|
|
34
|
+
npm install weaviate-ts-client # Weaviate
|
|
35
|
+
npm install @qdrant/js-client-rest # Qdrant
|
|
36
|
+
npm install chromadb # ChromaDB
|
|
37
|
+
|
|
38
|
+
# Additional Embedding Providers
|
|
39
|
+
npm install cohere-ai # Cohere
|
|
40
|
+
npm install @huggingface/inference # HuggingFace
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
### Basic RAG Pipeline
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import {
|
|
49
|
+
RAGPipeline,
|
|
50
|
+
MemoryVectorStore,
|
|
51
|
+
OpenAIEmbeddings,
|
|
52
|
+
RecursiveTextSplitter,
|
|
53
|
+
} from '@hazeljs/rag';
|
|
54
|
+
|
|
55
|
+
// 1. Setup embedding provider
|
|
56
|
+
const embeddings = new OpenAIEmbeddings({
|
|
57
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
58
|
+
model: 'text-embedding-3-small',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// 2. Setup vector store
|
|
62
|
+
const vectorStore = new MemoryVectorStore(embeddings);
|
|
63
|
+
|
|
64
|
+
// 3. Setup text splitter
|
|
65
|
+
const textSplitter = new RecursiveTextSplitter({
|
|
66
|
+
chunkSize: 1000,
|
|
67
|
+
chunkOverlap: 200,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// 4. Create RAG pipeline
|
|
71
|
+
const rag = new RAGPipeline({
|
|
72
|
+
vectorStore,
|
|
73
|
+
embeddingProvider: embeddings,
|
|
74
|
+
textSplitter,
|
|
75
|
+
topK: 5,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// 5. Initialize
|
|
79
|
+
await rag.initialize();
|
|
80
|
+
|
|
81
|
+
// 6. Add documents
|
|
82
|
+
await rag.addDocuments([
|
|
83
|
+
{
|
|
84
|
+
content: 'HazelJS is a modern TypeScript framework for building scalable applications.',
|
|
85
|
+
metadata: { source: 'docs', category: 'intro' },
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
content: 'The framework includes built-in support for microservices, caching, and AI.',
|
|
89
|
+
metadata: { source: 'docs', category: 'features' },
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
// 7. Query
|
|
94
|
+
const result = await rag.query('What is HazelJS?', {
|
|
95
|
+
topK: 3,
|
|
96
|
+
filter: { source: 'docs' },
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
console.log(result.answer);
|
|
100
|
+
console.log(result.sources);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### With LLM Integration
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import OpenAI from 'openai';
|
|
107
|
+
|
|
108
|
+
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });
|
|
109
|
+
|
|
110
|
+
// Create LLM function
|
|
111
|
+
const llmFunction = async (prompt: string) => {
|
|
112
|
+
const response = await openai.chat.completions.create({
|
|
113
|
+
model: 'gpt-4',
|
|
114
|
+
messages: [{ role: 'user', content: prompt }],
|
|
115
|
+
});
|
|
116
|
+
return response.choices[0].message.content || '';
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Create RAG pipeline with LLM
|
|
120
|
+
const rag = new RAGPipeline(config, llmFunction);
|
|
121
|
+
|
|
122
|
+
// Query with custom prompt
|
|
123
|
+
const result = await rag.query('What is HazelJS?', {
|
|
124
|
+
llmPrompt: `Based on the following context, answer the question.
|
|
125
|
+
|
|
126
|
+
Context:
|
|
127
|
+
{context}
|
|
128
|
+
|
|
129
|
+
Question: {query}
|
|
130
|
+
|
|
131
|
+
Answer:`,
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Vector Stores
|
|
136
|
+
|
|
137
|
+
### Memory Vector Store (Development)
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { MemoryVectorStore, OpenAIEmbeddings } from '@hazeljs/rag';
|
|
141
|
+
|
|
142
|
+
const embeddings = new OpenAIEmbeddings({ apiKey: process.env.OPENAI_API_KEY! });
|
|
143
|
+
const vectorStore = new MemoryVectorStore(embeddings);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Pinecone (Production)
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { Pinecone } from '@pinecone-database/pinecone';
|
|
150
|
+
import { PineconeVectorStore } from '@hazeljs/rag';
|
|
151
|
+
|
|
152
|
+
const pinecone = new Pinecone({ apiKey: process.env.PINECONE_API_KEY! });
|
|
153
|
+
const index = pinecone.index('my-index');
|
|
154
|
+
|
|
155
|
+
const vectorStore = new PineconeVectorStore(index, embeddings);
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Qdrant
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { QdrantClient } from '@qdrant/js-client-rest';
|
|
162
|
+
import { QdrantVectorStore } from '@hazeljs/rag';
|
|
163
|
+
|
|
164
|
+
const client = new QdrantClient({ url: 'http://localhost:6333' });
|
|
165
|
+
const vectorStore = new QdrantVectorStore(client, embeddings, {
|
|
166
|
+
collectionName: 'my-collection',
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Embedding Providers
|
|
171
|
+
|
|
172
|
+
### OpenAI
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { OpenAIEmbeddings } from '@hazeljs/rag';
|
|
176
|
+
|
|
177
|
+
const embeddings = new OpenAIEmbeddings({
|
|
178
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
179
|
+
model: 'text-embedding-3-small', // or 'text-embedding-3-large'
|
|
180
|
+
dimensions: 1536,
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Cohere
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { CohereEmbeddings } from '@hazeljs/rag';
|
|
188
|
+
|
|
189
|
+
const embeddings = new CohereEmbeddings({
|
|
190
|
+
apiKey: process.env.COHERE_API_KEY!,
|
|
191
|
+
model: 'embed-english-v3.0',
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### HuggingFace
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import { HuggingFaceEmbeddings } from '@hazeljs/rag';
|
|
199
|
+
|
|
200
|
+
const embeddings = new HuggingFaceEmbeddings({
|
|
201
|
+
apiKey: process.env.HUGGINGFACE_API_KEY!,
|
|
202
|
+
model: 'sentence-transformers/all-MiniLM-L6-v2',
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Text Splitting
|
|
207
|
+
|
|
208
|
+
### Recursive Text Splitter
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { RecursiveTextSplitter } from '@hazeljs/rag';
|
|
212
|
+
|
|
213
|
+
const splitter = new RecursiveTextSplitter({
|
|
214
|
+
chunkSize: 1000,
|
|
215
|
+
chunkOverlap: 200,
|
|
216
|
+
separators: ['\n\n', '\n', '. ', ' ', ''],
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const chunks = splitter.split(longText);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Retrieval Strategies
|
|
223
|
+
|
|
224
|
+
### Similarity Search (Default)
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
const results = await rag.retrieve('query', {
|
|
228
|
+
topK: 5,
|
|
229
|
+
strategy: RetrievalStrategy.SIMILARITY,
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### MMR (Maximal Marginal Relevance)
|
|
234
|
+
|
|
235
|
+
Balances relevance and diversity to avoid redundant results:
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
const results = await rag.retrieve('query', {
|
|
239
|
+
topK: 5,
|
|
240
|
+
strategy: RetrievalStrategy.MMR,
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Hybrid Search
|
|
245
|
+
|
|
246
|
+
Combines keyword and semantic search:
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
const results = await rag.retrieve('query', {
|
|
250
|
+
topK: 5,
|
|
251
|
+
strategy: RetrievalStrategy.HYBRID,
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Metadata Filtering
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
await rag.addDocuments([
|
|
259
|
+
{
|
|
260
|
+
content: 'Document 1',
|
|
261
|
+
metadata: { category: 'tech', year: 2024 },
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
content: 'Document 2',
|
|
265
|
+
metadata: { category: 'science', year: 2023 },
|
|
266
|
+
},
|
|
267
|
+
]);
|
|
268
|
+
|
|
269
|
+
// Filter by metadata
|
|
270
|
+
const results = await rag.query('query', {
|
|
271
|
+
filter: { category: 'tech', year: 2024 },
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Advanced Usage
|
|
276
|
+
|
|
277
|
+
### Custom Document Loaders
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
import { DocumentLoader, Document } from '@hazeljs/rag';
|
|
281
|
+
|
|
282
|
+
class PDFLoader implements DocumentLoader {
|
|
283
|
+
constructor(private filePath: string) {}
|
|
284
|
+
|
|
285
|
+
async load(): Promise<Document[]> {
|
|
286
|
+
// Load and parse PDF
|
|
287
|
+
const text = await this.parsePDF(this.filePath);
|
|
288
|
+
return [{ content: text, metadata: { source: this.filePath } }];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private async parsePDF(path: string): Promise<string> {
|
|
292
|
+
// PDF parsing logic
|
|
293
|
+
return '';
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const loader = new PDFLoader('./document.pdf');
|
|
298
|
+
const documents = await loader.load();
|
|
299
|
+
await rag.addDocuments(documents);
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Batch Operations
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
// Add multiple documents efficiently
|
|
306
|
+
const ids = await rag.addDocuments(documents);
|
|
307
|
+
|
|
308
|
+
// Delete multiple documents
|
|
309
|
+
await rag.deleteDocuments(ids);
|
|
310
|
+
|
|
311
|
+
// Clear all documents
|
|
312
|
+
await rag.clear();
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## API Reference
|
|
316
|
+
|
|
317
|
+
### RAGPipeline
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
class RAGPipeline {
|
|
321
|
+
constructor(config: RAGConfig, llmFunction?: LLMFunction);
|
|
322
|
+
initialize(): Promise<void>;
|
|
323
|
+
addDocuments(documents: Document[]): Promise<string[]>;
|
|
324
|
+
query(query: string, options?: RAGQueryOptions): Promise<RAGResponse>;
|
|
325
|
+
retrieve(query: string, options?: QueryOptions, strategy?: RetrievalStrategy): Promise<SearchResult[]>;
|
|
326
|
+
deleteDocuments(ids: string[]): Promise<void>;
|
|
327
|
+
clear(): Promise<void>;
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Types
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
interface Document {
|
|
335
|
+
id?: string;
|
|
336
|
+
content: string;
|
|
337
|
+
metadata?: Record<string, any>;
|
|
338
|
+
embedding?: number[];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
interface SearchResult {
|
|
342
|
+
id: string;
|
|
343
|
+
content: string;
|
|
344
|
+
metadata?: Record<string, any>;
|
|
345
|
+
score: number;
|
|
346
|
+
embedding?: number[];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
interface RAGResponse {
|
|
350
|
+
answer: string;
|
|
351
|
+
sources: SearchResult[];
|
|
352
|
+
context: string;
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## Use Cases
|
|
357
|
+
|
|
358
|
+
- 📖 **Documentation Search** - Semantic search across documentation
|
|
359
|
+
- 💬 **Chatbots** - Context-aware conversational AI
|
|
360
|
+
- 🔍 **Knowledge Base** - Internal knowledge management
|
|
361
|
+
- 📝 **Content Recommendations** - Similar content discovery
|
|
362
|
+
- 🎓 **Educational Tools** - Q&A systems with source citations
|
|
363
|
+
- 🏢 **Enterprise Search** - Semantic search across company data
|
|
364
|
+
|
|
365
|
+
## Performance Tips
|
|
366
|
+
|
|
367
|
+
1. **Batch Operations** - Add documents in batches for better performance
|
|
368
|
+
2. **Chunk Size** - Balance between context and precision (500-1500 tokens)
|
|
369
|
+
3. **Overlap** - Use 10-20% overlap for better context continuity
|
|
370
|
+
4. **Caching** - Cache embeddings for frequently accessed documents
|
|
371
|
+
5. **Filtering** - Use metadata filters to reduce search space
|
|
372
|
+
|
|
373
|
+
## License
|
|
374
|
+
|
|
375
|
+
MIT
|
|
376
|
+
|
|
377
|
+
## Contributing
|
|
378
|
+
|
|
379
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for details.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic RAG Service
|
|
3
|
+
* Main service class demonstrating all agentic RAG capabilities
|
|
4
|
+
*/
|
|
5
|
+
import { VectorStore, SearchResult, QueryOptions } from '../types';
|
|
6
|
+
import { AgenticLLMProvider } from './types';
|
|
7
|
+
export interface AgenticRAGServiceConfig {
|
|
8
|
+
vectorStore: VectorStore;
|
|
9
|
+
llmProvider?: AgenticLLMProvider;
|
|
10
|
+
enableAllFeatures?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class AgenticRAGService {
|
|
13
|
+
private vectorStore;
|
|
14
|
+
private llmProvider?;
|
|
15
|
+
constructor(config: AgenticRAGServiceConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Basic retrieval with all agentic features
|
|
18
|
+
*/
|
|
19
|
+
retrieve(query: string, options?: QueryOptions): Promise<SearchResult[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Advanced retrieval with HyDE
|
|
22
|
+
*/
|
|
23
|
+
hydeRetrieve(query: string, options?: QueryOptions): Promise<SearchResult[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Multi-hop reasoning retrieval
|
|
26
|
+
*/
|
|
27
|
+
deepRetrieve(query: string, options?: QueryOptions): Promise<SearchResult[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Context-aware conversational retrieval
|
|
30
|
+
*/
|
|
31
|
+
conversationalRetrieve(query: string, sessionId: string, options?: QueryOptions): Promise<SearchResult[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Verified retrieval with source checking
|
|
34
|
+
*/
|
|
35
|
+
verifiedRetrieve(query: string, options?: QueryOptions): Promise<SearchResult[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Learning-enabled retrieval
|
|
38
|
+
*/
|
|
39
|
+
learningRetrieve(query: string, options?: QueryOptions): Promise<SearchResult[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Provide feedback for active learning
|
|
42
|
+
*/
|
|
43
|
+
provideFeedback(_resultId: string, _rating: number, _relevant: boolean): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Combined: All features enabled
|
|
46
|
+
*/
|
|
47
|
+
superRetrieve(query: string, sessionId: string, options?: QueryOptions): Promise<SearchResult[]>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=agentic-rag.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentic-rag.service.d.ts","sourceRoot":"","sources":["../../src/agentic/agentic-rag.service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAgB7C,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAC,CAAqB;gBAE7B,MAAM,EAAE,uBAAuB;IAK3C;;OAEG;IAKG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAI9E;;OAEG;IAIG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAIlF;;OAEG;IAEG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAIlF;;OAEG;IAIG,sBAAsB,CAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,YAAY,EAAE,CAAC;IAO1B;;OAEG;IAOG,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAItF;;OAEG;IAGG,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAItF;;OAEG;IAEG,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5F;;OAEG;IAWG,aAAa,CACjB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,YAAY,EAAE,CAAC;CAM3B"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agentic RAG Service
|
|
4
|
+
* Main service class demonstrating all agentic RAG capabilities
|
|
5
|
+
*/
|
|
6
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
7
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11
|
+
};
|
|
12
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.AgenticRAGService = void 0;
|
|
17
|
+
const decorators_1 = require("./decorators");
|
|
18
|
+
class AgenticRAGService {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.vectorStore = config.vectorStore;
|
|
21
|
+
this.llmProvider = config.llmProvider;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Basic retrieval with all agentic features
|
|
25
|
+
*/
|
|
26
|
+
async retrieve(query, options) {
|
|
27
|
+
return this.vectorStore.search(query, options);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Advanced retrieval with HyDE
|
|
31
|
+
*/
|
|
32
|
+
async hydeRetrieve(query, options) {
|
|
33
|
+
return this.vectorStore.search(query, options);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Multi-hop reasoning retrieval
|
|
37
|
+
*/
|
|
38
|
+
async deepRetrieve(query, options) {
|
|
39
|
+
return this.vectorStore.search(query, options);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Context-aware conversational retrieval
|
|
43
|
+
*/
|
|
44
|
+
async conversationalRetrieve(query, sessionId, options) {
|
|
45
|
+
return this.vectorStore.search(query, {
|
|
46
|
+
...options,
|
|
47
|
+
sessionId: sessionId,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Verified retrieval with source checking
|
|
52
|
+
*/
|
|
53
|
+
async verifiedRetrieve(query, options) {
|
|
54
|
+
return this.vectorStore.search(query, options);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Learning-enabled retrieval
|
|
58
|
+
*/
|
|
59
|
+
async learningRetrieve(query, options) {
|
|
60
|
+
return this.vectorStore.search(query, options);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Provide feedback for active learning
|
|
64
|
+
*/
|
|
65
|
+
async provideFeedback(_resultId, _rating, _relevant) {
|
|
66
|
+
// Feedback is stored by decorator
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Combined: All features enabled
|
|
70
|
+
*/
|
|
71
|
+
async superRetrieve(query, sessionId, options) {
|
|
72
|
+
return this.vectorStore.search(query, {
|
|
73
|
+
...options,
|
|
74
|
+
sessionId: sessionId,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.AgenticRAGService = AgenticRAGService;
|
|
79
|
+
__decorate([
|
|
80
|
+
(0, decorators_1.QueryPlanner)({ decompose: true, maxSubQueries: 5, parallel: true }),
|
|
81
|
+
(0, decorators_1.SelfReflective)({ maxIterations: 3, qualityThreshold: 0.8 }),
|
|
82
|
+
(0, decorators_1.AdaptiveRetrieval)({ autoSelect: true, contextAware: true }),
|
|
83
|
+
(0, decorators_1.Cached)({ ttl: 3600 }),
|
|
84
|
+
__metadata("design:type", Function),
|
|
85
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
86
|
+
__metadata("design:returntype", Promise)
|
|
87
|
+
], AgenticRAGService.prototype, "retrieve", null);
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, decorators_1.HyDE)({ generateHypothesis: true, numHypotheses: 3 }),
|
|
90
|
+
(0, decorators_1.CorrectiveRAG)({ relevanceThreshold: 0.7, fallbackToWeb: true }),
|
|
91
|
+
(0, decorators_1.Cached)({ ttl: 1800 }),
|
|
92
|
+
__metadata("design:type", Function),
|
|
93
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
94
|
+
__metadata("design:returntype", Promise)
|
|
95
|
+
], AgenticRAGService.prototype, "hydeRetrieve", null);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, decorators_1.MultiHop)({ maxHops: 3, strategy: 'breadth-first' }),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
100
|
+
__metadata("design:returntype", Promise)
|
|
101
|
+
], AgenticRAGService.prototype, "deepRetrieve", null);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, decorators_1.ContextAware)({ windowSize: 5, entityTracking: true, topicModeling: true }),
|
|
104
|
+
(0, decorators_1.QueryRewriter)({ techniques: ['expansion', 'synonym'], llmBased: true }),
|
|
105
|
+
(0, decorators_1.Cached)({ ttl: 600 }),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
108
|
+
__metadata("design:returntype", Promise)
|
|
109
|
+
], AgenticRAGService.prototype, "conversationalRetrieve", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, decorators_1.SourceVerification)({
|
|
112
|
+
checkFreshness: true,
|
|
113
|
+
verifyAuthority: true,
|
|
114
|
+
requireCitations: true,
|
|
115
|
+
}),
|
|
116
|
+
(0, decorators_1.SelfReflective)({ maxIterations: 2, qualityThreshold: 0.85 }),
|
|
117
|
+
__metadata("design:type", Function),
|
|
118
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
119
|
+
__metadata("design:returntype", Promise)
|
|
120
|
+
], AgenticRAGService.prototype, "verifiedRetrieve", null);
|
|
121
|
+
__decorate([
|
|
122
|
+
(0, decorators_1.ActiveLearning)({ feedbackEnabled: true, retrainThreshold: 100 }),
|
|
123
|
+
(0, decorators_1.AdaptiveRetrieval)({ autoSelect: true }),
|
|
124
|
+
__metadata("design:type", Function),
|
|
125
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
126
|
+
__metadata("design:returntype", Promise)
|
|
127
|
+
], AgenticRAGService.prototype, "learningRetrieve", null);
|
|
128
|
+
__decorate([
|
|
129
|
+
(0, decorators_1.Feedback)(),
|
|
130
|
+
__metadata("design:type", Function),
|
|
131
|
+
__metadata("design:paramtypes", [String, Number, Boolean]),
|
|
132
|
+
__metadata("design:returntype", Promise)
|
|
133
|
+
], AgenticRAGService.prototype, "provideFeedback", null);
|
|
134
|
+
__decorate([
|
|
135
|
+
(0, decorators_1.QueryPlanner)({ decompose: true, maxSubQueries: 5 }),
|
|
136
|
+
(0, decorators_1.SelfReflective)({ maxIterations: 3, qualityThreshold: 0.8 }),
|
|
137
|
+
(0, decorators_1.AdaptiveRetrieval)({ autoSelect: true, contextAware: true }),
|
|
138
|
+
(0, decorators_1.HyDE)({ generateHypothesis: true, numHypotheses: 2 }),
|
|
139
|
+
(0, decorators_1.CorrectiveRAG)({ relevanceThreshold: 0.7 }),
|
|
140
|
+
(0, decorators_1.ContextAware)({ windowSize: 5, entityTracking: true }),
|
|
141
|
+
(0, decorators_1.QueryRewriter)({ techniques: ['expansion', 'synonym'] }),
|
|
142
|
+
(0, decorators_1.SourceVerification)({ checkFreshness: true, verifyAuthority: true }),
|
|
143
|
+
(0, decorators_1.ActiveLearning)({ feedbackEnabled: true }),
|
|
144
|
+
(0, decorators_1.Cached)({ ttl: 3600 }),
|
|
145
|
+
__metadata("design:type", Function),
|
|
146
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
147
|
+
__metadata("design:returntype", Promise)
|
|
148
|
+
], AgenticRAGService.prototype, "superRetrieve", null);
|
|
149
|
+
//# sourceMappingURL=agentic-rag.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentic-rag.service.js","sourceRoot":"","sources":["../../src/agentic/agentic-rag.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Active Learning Decorator
|
|
3
|
+
* Learns from user feedback to improve retrieval
|
|
4
|
+
*/
|
|
5
|
+
import 'reflect-metadata';
|
|
6
|
+
export interface ActiveLearningConfig {
|
|
7
|
+
feedbackEnabled?: boolean;
|
|
8
|
+
retrainThreshold?: number;
|
|
9
|
+
storageKey?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function ActiveLearning(config?: ActiveLearningConfig): MethodDecorator;
|
|
12
|
+
export declare function Feedback(): MethodDecorator;
|
|
13
|
+
export declare function getFeedbackStats(storageKey?: string): {
|
|
14
|
+
totalFeedback: number;
|
|
15
|
+
avgRating: number;
|
|
16
|
+
relevantCount: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function clearFeedback(storageKey?: string): void;
|
|
19
|
+
//# sourceMappingURL=active-learning.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-learning.decorator.d.ts","sourceRoot":"","sources":["../../../src/agentic/decorators/active-learning.decorator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,kBAAkB,CAAC;AAG1B,MAAM,WAAW,oBAAoB;IACnC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,wBAAgB,cAAc,CAAC,MAAM,GAAE,oBAAyB,GAAG,eAAe,CAmBjF;AAED,wBAAgB,QAAQ,IAAI,eAAe,CAkB1C;AAqDD,wBAAgB,gBAAgB,CAAC,UAAU,GAAE,MAAkB,GAAG;IAChE,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB,CAeA;AAED,wBAAgB,aAAa,CAAC,UAAU,GAAE,MAAkB,GAAG,IAAI,CAElE"}
|