@hazeljs/rag 0.7.9 → 0.8.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 +49 -50
- package/dist/decorators/semantic-search.decorator.d.ts +6 -2
- package/dist/decorators/semantic-search.decorator.d.ts.map +1 -1
- package/dist/decorators/semantic-search.decorator.js +21 -4
- package/dist/decorators/semantic-search.decorator.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/package.json +8 -50
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ Part of the HazelJS AI-Native Backend Framework. Load documents from any source,
|
|
|
15
15
|
Built for **AI-native applications** - not just another RAG library. When you combine @hazeljs/rag with @hazeljs/core, @hazeljs/ai, and @hazeljs/agent, you get a complete stack for intelligent backends.
|
|
16
16
|
|
|
17
17
|
**Perfect for:**
|
|
18
|
+
|
|
18
19
|
- AI startups building knowledge-based applications
|
|
19
20
|
- Teams implementing document Q&A systems
|
|
20
21
|
- Developers who want semantic search without complexity
|
|
@@ -110,19 +111,19 @@ Every loader extends `BaseDocumentLoader` and returns `Document[]` ready for chu
|
|
|
110
111
|
|
|
111
112
|
### Built-in loaders
|
|
112
113
|
|
|
113
|
-
| Loader
|
|
114
|
-
|
|
115
|
-
| `TextFileLoader`
|
|
116
|
-
| `MarkdownFileLoader`
|
|
117
|
-
| `JSONFileLoader`
|
|
118
|
-
| `CSVFileLoader`
|
|
119
|
-
| `HtmlFileLoader`
|
|
120
|
-
| `DirectoryLoader`
|
|
121
|
-
| `PdfLoader`
|
|
122
|
-
| `DocxLoader`
|
|
123
|
-
| `WebLoader`
|
|
124
|
-
| `YouTubeTranscriptLoader` | YouTube transcripts; no API key; segment by duration
|
|
125
|
-
| `GitHubLoader`
|
|
114
|
+
| Loader | Source | Extra install |
|
|
115
|
+
| ------------------------- | -------------------------------------------------------- | :-----------: |
|
|
116
|
+
| `TextFileLoader` | `.txt` files | — |
|
|
117
|
+
| `MarkdownFileLoader` | `.md` / `.mdx` with heading splits and YAML front-matter | — |
|
|
118
|
+
| `JSONFileLoader` | `.json` with `textKey` / JSON Pointer extraction | — |
|
|
119
|
+
| `CSVFileLoader` | `.csv` rows mapped to documents | — |
|
|
120
|
+
| `HtmlFileLoader` | `.html` tag stripping; optional CSS selector via cheerio | opt. |
|
|
121
|
+
| `DirectoryLoader` | Recursive walk; auto-detects loader by extension | — |
|
|
122
|
+
| `PdfLoader` | PDFs; split by page or full document | `pdf-parse` |
|
|
123
|
+
| `DocxLoader` | Word documents; plain text or HTML output | `mammoth` |
|
|
124
|
+
| `WebLoader` | HTTP scraping with retry/timeout; optional CSS selector | opt. |
|
|
125
|
+
| `YouTubeTranscriptLoader` | YouTube transcripts; no API key; segment by duration | — |
|
|
126
|
+
| `GitHubLoader` | GitHub REST API; filter by path, extension, `maxFiles` | — |
|
|
126
127
|
|
|
127
128
|
### Examples
|
|
128
129
|
|
|
@@ -176,7 +177,7 @@ const webDocs = await new WebLoader({
|
|
|
176
177
|
// YouTube transcript (no API key needed)
|
|
177
178
|
const ytDocs = await new YouTubeTranscriptLoader({
|
|
178
179
|
videoUrl: 'https://www.youtube.com/watch?v=VIDEO_ID',
|
|
179
|
-
segmentDuration: 60,
|
|
180
|
+
segmentDuration: 60, // group into 60-second chunks
|
|
180
181
|
}).load();
|
|
181
182
|
|
|
182
183
|
// GitHub repository
|
|
@@ -203,12 +204,14 @@ import { BaseDocumentLoader, Loader, DocumentLoaderRegistry } from '@hazeljs/rag
|
|
|
203
204
|
|
|
204
205
|
@Loader({ name: 'NotionLoader', extensions: [] })
|
|
205
206
|
export class NotionLoader extends BaseDocumentLoader {
|
|
206
|
-
constructor(private readonly databaseId: string) {
|
|
207
|
+
constructor(private readonly databaseId: string) {
|
|
208
|
+
super();
|
|
209
|
+
}
|
|
207
210
|
|
|
208
211
|
async load() {
|
|
209
212
|
const pages = await fetchNotionPages(this.databaseId);
|
|
210
|
-
return pages.map(p =>
|
|
211
|
-
this.createDocument(p.content, { source: `notion:${p.id}`, title: p.title })
|
|
213
|
+
return pages.map((p) =>
|
|
214
|
+
this.createDocument(p.content, { source: `notion:${p.id}`, title: p.title })
|
|
212
215
|
);
|
|
213
216
|
}
|
|
214
217
|
}
|
|
@@ -225,12 +228,12 @@ GraphRAG builds a **knowledge graph** from your documents — entities, relation
|
|
|
225
228
|
|
|
226
229
|
### Why GraphRAG?
|
|
227
230
|
|
|
228
|
-
| Question type
|
|
229
|
-
|
|
230
|
-
| "What does X do?"
|
|
231
|
-
| "How do X and Y relate?"
|
|
232
|
-
| "What are the main architectural layers?" | ❌ Poor
|
|
233
|
-
| Multi-document cross-referencing
|
|
231
|
+
| Question type | Traditional RAG | GraphRAG |
|
|
232
|
+
| ----------------------------------------- | --------------- | -------------------------------- |
|
|
233
|
+
| "What does X do?" | ✅ Good | ✅ Excellent (entity traversal) |
|
|
234
|
+
| "How do X and Y relate?" | ❌ Poor | ✅ Excellent (relationships) |
|
|
235
|
+
| "What are the main architectural layers?" | ❌ Poor | ✅ Excellent (community reports) |
|
|
236
|
+
| Multi-document cross-referencing | ❌ Fragmented | ✅ Native |
|
|
234
237
|
|
|
235
238
|
### Build the graph
|
|
236
239
|
|
|
@@ -250,12 +253,12 @@ const graphRag = new GraphRAGPipeline({
|
|
|
250
253
|
});
|
|
251
254
|
return res.choices[0].message.content ?? '';
|
|
252
255
|
},
|
|
253
|
-
extractionChunkSize: 2000,
|
|
256
|
+
extractionChunkSize: 2000, // chars per LLM extraction call
|
|
254
257
|
generateCommunityReports: true, // LLM summaries per community cluster
|
|
255
|
-
maxCommunitySize: 15,
|
|
256
|
-
localSearchDepth: 2,
|
|
257
|
-
localSearchTopK: 5,
|
|
258
|
-
globalSearchTopK: 5,
|
|
258
|
+
maxCommunitySize: 15, // split clusters larger than this
|
|
259
|
+
localSearchDepth: 2, // BFS hops for local search
|
|
260
|
+
localSearchTopK: 5, // seed entities per query
|
|
261
|
+
globalSearchTopK: 5, // community reports for global search
|
|
259
262
|
});
|
|
260
263
|
|
|
261
264
|
const docs = await new DirectoryLoader({ dirPath: './knowledge-base', recursive: true }).load();
|
|
@@ -269,21 +272,17 @@ const stats = await graphRag.build(docs);
|
|
|
269
272
|
```typescript
|
|
270
273
|
// LOCAL — entity-centric, BFS graph traversal
|
|
271
274
|
// Best for: specific questions about named concepts, classes, or technologies
|
|
272
|
-
const local = await graphRag.search(
|
|
273
|
-
'How does dependency injection work?',
|
|
274
|
-
{ mode: 'local' },
|
|
275
|
-
);
|
|
275
|
+
const local = await graphRag.search('How does dependency injection work?', { mode: 'local' });
|
|
276
276
|
console.log(local.answer);
|
|
277
|
-
console.log(local.entities);
|
|
277
|
+
console.log(local.entities); // entities found and traversed
|
|
278
278
|
console.log(local.relationships); // evidence relationships
|
|
279
279
|
|
|
280
280
|
// GLOBAL — community report ranking
|
|
281
281
|
// Best for: broad thematic questions, architecture overviews
|
|
282
|
-
const global = await graphRag.search(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
);
|
|
286
|
-
console.log(global.communities); // ranked community reports used
|
|
282
|
+
const global = await graphRag.search('What are the main architectural layers of this system?', {
|
|
283
|
+
mode: 'global',
|
|
284
|
+
});
|
|
285
|
+
console.log(global.communities); // ranked community reports used
|
|
287
286
|
|
|
288
287
|
// HYBRID — runs both in parallel, single synthesis call (recommended default)
|
|
289
288
|
const result = await graphRag.search('What vector stores does @hazeljs/rag support?');
|
|
@@ -307,11 +306,11 @@ const graph = graphRag.getGraph();
|
|
|
307
306
|
// Entities, relationships, community reports
|
|
308
307
|
console.log([...graph.entities.values()].slice(0, 5));
|
|
309
308
|
console.log([...graph.relationships.values()].slice(0, 5));
|
|
310
|
-
console.log([...graph.communityReports.values()].map(r => r.title));
|
|
309
|
+
console.log([...graph.communityReports.values()].map((r) => r.title));
|
|
311
310
|
|
|
312
311
|
// Statistics
|
|
313
312
|
const stats = graphRag.getStats();
|
|
314
|
-
console.log(stats.entityTypeBreakdown);
|
|
313
|
+
console.log(stats.entityTypeBreakdown); // { TECHNOLOGY: 14, CONCEPT: 12, ... }
|
|
315
314
|
console.log(stats.topEntities.slice(0, 5)); // most-connected entities
|
|
316
315
|
```
|
|
317
316
|
|
|
@@ -358,12 +357,12 @@ const vectorStore = new ChromaVectorStore(embeddings, {
|
|
|
358
357
|
|
|
359
358
|
### Vector store comparison
|
|
360
359
|
|
|
361
|
-
|
|
|
362
|
-
|
|
363
|
-
| Setup
|
|
364
|
-
| Persistence |
|
|
365
|
-
| Best for
|
|
366
|
-
| Cost
|
|
360
|
+
| | Memory | Pinecone | Qdrant | Weaviate | ChromaDB |
|
|
361
|
+
| ----------- | :------: | :--------: | :-------: | :------: | :---------: |
|
|
362
|
+
| Setup | None | API Key | Docker | Docker | Docker |
|
|
363
|
+
| Persistence | ❌ | ✅ | ✅ | ✅ | ✅ |
|
|
364
|
+
| Best for | Dev/Test | Production | High-perf | GraphQL | Prototyping |
|
|
365
|
+
| Cost | Free | Paid | OSS | OSS | OSS |
|
|
367
366
|
|
|
368
367
|
---
|
|
369
368
|
|
|
@@ -375,7 +374,7 @@ import { OpenAIEmbeddings, CohereEmbeddings } from '@hazeljs/rag';
|
|
|
375
374
|
// OpenAI
|
|
376
375
|
const openaiEmbed = new OpenAIEmbeddings({
|
|
377
376
|
apiKey: process.env.OPENAI_API_KEY,
|
|
378
|
-
model: 'text-embedding-3-small',
|
|
377
|
+
model: 'text-embedding-3-small', // 1536 dims
|
|
379
378
|
// model: 'text-embedding-3-large', // 3072 dims, highest quality
|
|
380
379
|
});
|
|
381
380
|
|
|
@@ -418,8 +417,8 @@ const results2 = await multiQuery.search('How do I deploy my app?', { topK: 5 })
|
|
|
418
417
|
import { RecursiveTextSplitter } from '@hazeljs/rag';
|
|
419
418
|
|
|
420
419
|
const splitter = new RecursiveTextSplitter({
|
|
421
|
-
chunkSize: 1000,
|
|
422
|
-
chunkOverlap: 200,
|
|
420
|
+
chunkSize: 1000, // target chars per chunk
|
|
421
|
+
chunkOverlap: 200, // overlap for context continuity
|
|
423
422
|
separators: ['\n\n', '\n', '. ', ' '],
|
|
424
423
|
});
|
|
425
424
|
|
|
@@ -448,7 +447,7 @@ const rag = new RAGPipelineWithMemory(config, memory, llmFunction);
|
|
|
448
447
|
const response = await rag.queryWithMemory(
|
|
449
448
|
'What did we discuss about deployment?',
|
|
450
449
|
'session-123',
|
|
451
|
-
'user-456'
|
|
450
|
+
'user-456'
|
|
452
451
|
);
|
|
453
452
|
console.log(response.answer);
|
|
454
453
|
console.log(response.memories);
|
|
@@ -14,6 +14,10 @@ export interface HybridSearchOptions extends SemanticSearchOptions {
|
|
|
14
14
|
keywordWeight?: number;
|
|
15
15
|
algorithm?: 'rrf' | 'weighted' | 'linear';
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Register a global handler for {@link AutoEmbed} (e.g. upsert into your vector index).
|
|
19
|
+
*/
|
|
20
|
+
export declare function configureAutoEmbed(handler: (text: string) => Promise<void>): void;
|
|
17
21
|
/**
|
|
18
22
|
* Enables semantic search on a method
|
|
19
23
|
*/
|
|
@@ -23,9 +27,9 @@ export declare function SemanticSearch(options?: SemanticSearchOptions): MethodD
|
|
|
23
27
|
*/
|
|
24
28
|
export declare function HybridSearch(options?: HybridSearchOptions): MethodDecorator;
|
|
25
29
|
/**
|
|
26
|
-
* Auto-embed decorator
|
|
30
|
+
* Auto-embed decorator — after the method returns, text fields are passed to {@link configureAutoEmbed}.
|
|
27
31
|
*/
|
|
28
|
-
export declare function AutoEmbed(
|
|
32
|
+
export declare function AutoEmbed(fields?: string[]): MethodDecorator;
|
|
29
33
|
/**
|
|
30
34
|
* Multi-query RAG decorator
|
|
31
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic-search.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/semantic-search.decorator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,kBAAkB,CAAC;AAE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AC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,eAAe,CAuB5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,eAAe,CAKjF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,eAAe,CAKrF;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,eAAe,CAK9C;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,eAAe,CAKvF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,CAKtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACf,GACL,eAAe,CAKjB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,eAAe,CAK3F"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Enable semantic search capabilities on methods
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.configureAutoEmbed = configureAutoEmbed;
|
|
7
8
|
exports.SemanticSearch = SemanticSearch;
|
|
8
9
|
exports.HybridSearch = HybridSearch;
|
|
9
10
|
exports.AutoEmbed = AutoEmbed;
|
|
@@ -17,6 +18,14 @@ exports.TimeWeightedRetrieval = TimeWeightedRetrieval;
|
|
|
17
18
|
require("reflect-metadata");
|
|
18
19
|
const SEMANTIC_SEARCH_KEY = Symbol('semanticSearch');
|
|
19
20
|
const HYBRID_SEARCH_KEY = Symbol('hybridSearch');
|
|
21
|
+
/** Optional hook: embed text after entity persistence (wire to RAGPipeline / embedding provider). */
|
|
22
|
+
let autoEmbedHandler;
|
|
23
|
+
/**
|
|
24
|
+
* Register a global handler for {@link AutoEmbed} (e.g. upsert into your vector index).
|
|
25
|
+
*/
|
|
26
|
+
function configureAutoEmbed(handler) {
|
|
27
|
+
autoEmbedHandler = handler;
|
|
28
|
+
}
|
|
20
29
|
/**
|
|
21
30
|
* Enables semantic search on a method
|
|
22
31
|
*/
|
|
@@ -36,15 +45,23 @@ function HybridSearch(options = {}) {
|
|
|
36
45
|
};
|
|
37
46
|
}
|
|
38
47
|
/**
|
|
39
|
-
* Auto-embed decorator
|
|
48
|
+
* Auto-embed decorator — after the method returns, text fields are passed to {@link configureAutoEmbed}.
|
|
40
49
|
*/
|
|
41
|
-
function AutoEmbed(
|
|
50
|
+
function AutoEmbed(fields) {
|
|
42
51
|
return (target, propertyKey, descriptor) => {
|
|
43
52
|
const originalMethod = descriptor.value;
|
|
44
53
|
descriptor.value = async function (...args) {
|
|
45
54
|
const result = await originalMethod.apply(this, args);
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
if (autoEmbedHandler && result && typeof result === 'object') {
|
|
56
|
+
const obj = result;
|
|
57
|
+
const keys = fields?.length ? fields : Object.keys(obj);
|
|
58
|
+
for (const k of keys) {
|
|
59
|
+
const v = obj[k];
|
|
60
|
+
if (typeof v === 'string' && v.trim()) {
|
|
61
|
+
await autoEmbedHandler(v);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
48
65
|
return result;
|
|
49
66
|
};
|
|
50
67
|
return descriptor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic-search.decorator.js","sourceRoot":"","sources":["../../src/decorators/semantic-search.decorator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;
|
|
1
|
+
{"version":3,"file":"semantic-search.decorator.js","sourceRoot":"","sources":["../../src/decorators/semantic-search.decorator.ts"],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'./decorators/rag.decorator';
|
|
10
10
|
export * from './decorators/embeddable.decorator';
|
|
11
|
-
export
|
|
11
|
+
export { SemanticSearch, HybridSearch, AutoEmbed, configureAutoEmbed, MultiQueryRAG, CompressContext, SelfQueryRAG, Rerank, ParentChildRetrieval, EnsembleRetrieval, TimeWeightedRetrieval, } from './decorators/semantic-search.decorator';
|
|
12
12
|
export * from './embeddings/openai-embeddings';
|
|
13
13
|
export * from './embeddings/cohere-embeddings';
|
|
14
14
|
export * from './reranking/cohere.reranker';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAG7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAG7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,OAAO,EACL,cAAc,EACd,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,MAAM,EACN,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,wCAAwC,CAAC;AAGhD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAG5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAG7C,cAAc,0CAA0C,CAAC;AAGzD,cAAc,WAAW,CAAC;AAG1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AAGxC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,UAAU,CAAC;AACzB,cAAc,4BAA4B,CAAC;AAG3C,cAAc,WAAW,CAAC;AAG1B,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG5D,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.setDebugEnabled = exports.debug = exports.RAGErrorCode = exports.RAGError = void 0;
|
|
21
|
+
exports.setDebugEnabled = exports.debug = exports.RAGErrorCode = exports.RAGError = exports.TimeWeightedRetrieval = exports.EnsembleRetrieval = exports.ParentChildRetrieval = exports.Rerank = exports.SelfQueryRAG = exports.CompressContext = exports.MultiQueryRAG = exports.configureAutoEmbed = exports.AutoEmbed = exports.HybridSearch = exports.SemanticSearch = void 0;
|
|
22
22
|
// Core types
|
|
23
23
|
__exportStar(require("./types"), exports);
|
|
24
24
|
// RAG Pipeline
|
|
@@ -29,7 +29,18 @@ __exportStar(require("./rag.module"), exports);
|
|
|
29
29
|
// Decorators
|
|
30
30
|
__exportStar(require("./decorators/rag.decorator"), exports);
|
|
31
31
|
__exportStar(require("./decorators/embeddable.decorator"), exports);
|
|
32
|
-
|
|
32
|
+
var semantic_search_decorator_1 = require("./decorators/semantic-search.decorator");
|
|
33
|
+
Object.defineProperty(exports, "SemanticSearch", { enumerable: true, get: function () { return semantic_search_decorator_1.SemanticSearch; } });
|
|
34
|
+
Object.defineProperty(exports, "HybridSearch", { enumerable: true, get: function () { return semantic_search_decorator_1.HybridSearch; } });
|
|
35
|
+
Object.defineProperty(exports, "AutoEmbed", { enumerable: true, get: function () { return semantic_search_decorator_1.AutoEmbed; } });
|
|
36
|
+
Object.defineProperty(exports, "configureAutoEmbed", { enumerable: true, get: function () { return semantic_search_decorator_1.configureAutoEmbed; } });
|
|
37
|
+
Object.defineProperty(exports, "MultiQueryRAG", { enumerable: true, get: function () { return semantic_search_decorator_1.MultiQueryRAG; } });
|
|
38
|
+
Object.defineProperty(exports, "CompressContext", { enumerable: true, get: function () { return semantic_search_decorator_1.CompressContext; } });
|
|
39
|
+
Object.defineProperty(exports, "SelfQueryRAG", { enumerable: true, get: function () { return semantic_search_decorator_1.SelfQueryRAG; } });
|
|
40
|
+
Object.defineProperty(exports, "Rerank", { enumerable: true, get: function () { return semantic_search_decorator_1.Rerank; } });
|
|
41
|
+
Object.defineProperty(exports, "ParentChildRetrieval", { enumerable: true, get: function () { return semantic_search_decorator_1.ParentChildRetrieval; } });
|
|
42
|
+
Object.defineProperty(exports, "EnsembleRetrieval", { enumerable: true, get: function () { return semantic_search_decorator_1.EnsembleRetrieval; } });
|
|
43
|
+
Object.defineProperty(exports, "TimeWeightedRetrieval", { enumerable: true, get: function () { return semantic_search_decorator_1.TimeWeightedRetrieval; } });
|
|
33
44
|
// Embeddings & Reranking
|
|
34
45
|
__exportStar(require("./embeddings/openai-embeddings"), exports);
|
|
35
46
|
__exportStar(require("./embeddings/cohere-embeddings"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;AAEH,aAAa;AACb,0CAAwB;AAExB,eAAe;AACf,iDAA+B;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@@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hazeljs/rag",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Retrieval-Augmented Generation (RAG) and vector search for HazelJS framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "rm -rf dist tsconfig.tsbuildinfo && tsc --skipLibCheck",
|
|
22
|
-
"test": "jest --coverage --passWithNoTests",
|
|
22
|
+
"test": "jest --config jest.config.js --coverage --passWithNoTests",
|
|
23
23
|
"lint": "eslint \"src/**/*.ts\"",
|
|
24
24
|
"lint:fix": "eslint \"src/**/*.ts\" --fix",
|
|
25
|
-
"clean": "rm -rf dist"
|
|
25
|
+
"clean": "rm -rf dist && find src -type f \\( -name '*.js' -o -name '*.d.ts' -o -name '*.d.ts.map' \\) -delete 2>/dev/null || true"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@hazeljs/prompts": "^0.
|
|
28
|
+
"@hazeljs/prompts": "^0.8.1",
|
|
29
29
|
"reflect-metadata": "^0.2.2"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"chromadb": "^1.8.0",
|
|
40
40
|
"cohere-ai": "^7.0.0",
|
|
41
41
|
"mammoth": "^1.11.0",
|
|
42
|
-
"openai": "^
|
|
42
|
+
"openai": "^6.0.0",
|
|
43
43
|
"pdf-parse": "^1.1.1",
|
|
44
44
|
"weaviate-ts-client": "^2.0.0"
|
|
45
45
|
},
|
|
@@ -78,56 +78,14 @@
|
|
|
78
78
|
"optional": true
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
|
-
"jest": {
|
|
82
|
-
"preset": "ts-jest",
|
|
83
|
-
"testEnvironment": "node",
|
|
84
|
-
"testMatch": [
|
|
85
|
-
"**/src/__tests__/**/*.test.ts"
|
|
86
|
-
],
|
|
87
|
-
"moduleNameMapper": {
|
|
88
|
-
"^@hazeljs/prompts$": "<rootDir>/../prompts/src/index.ts",
|
|
89
|
-
"^@hazeljs/memory$": "<rootDir>/../memory/src/index.ts",
|
|
90
|
-
"^@hazeljs/memory/prisma$": "<rootDir>/../memory/src/prisma.ts"
|
|
91
|
-
},
|
|
92
|
-
"collectCoverageFrom": [
|
|
93
|
-
"src/**/*.ts",
|
|
94
|
-
"!src/**/*.d.ts",
|
|
95
|
-
"!src/index.ts",
|
|
96
|
-
"!src/rag.module.ts",
|
|
97
|
-
"!src/rag.service.ts",
|
|
98
|
-
"!src/rag-pipeline-with-memory.ts",
|
|
99
|
-
"!src/vector-stores/**",
|
|
100
|
-
"!src/embeddings/**",
|
|
101
|
-
"!src/agentic/**",
|
|
102
|
-
"!src/decorators/**",
|
|
103
|
-
"!src/memory/**",
|
|
104
|
-
"!src/loaders/pdf.loader.ts",
|
|
105
|
-
"!src/loaders/docx.loader.ts",
|
|
106
|
-
"!src/loaders/web.loader.ts",
|
|
107
|
-
"!src/loaders/github.loader.ts",
|
|
108
|
-
"!src/loaders/youtube-transcript.loader.ts",
|
|
109
|
-
"!src/loaders/index.ts",
|
|
110
|
-
"!src/graph/index.ts",
|
|
111
|
-
"!src/prompts/**",
|
|
112
|
-
"!src/types/**"
|
|
113
|
-
],
|
|
114
|
-
"coverageThreshold": {
|
|
115
|
-
"global": {
|
|
116
|
-
"statements": 85,
|
|
117
|
-
"branches": 75,
|
|
118
|
-
"functions": 85,
|
|
119
|
-
"lines": 85
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
81
|
"devDependencies": {
|
|
124
|
-
"@hazeljs/memory": "^0.
|
|
82
|
+
"@hazeljs/memory": "^0.8.1",
|
|
125
83
|
"@types/node": "^20.19.39",
|
|
126
84
|
"@typescript-eslint/eslint-plugin": "^8.58.0",
|
|
127
85
|
"@typescript-eslint/parser": "^8.58.0",
|
|
128
86
|
"eslint": "^8.57.1",
|
|
129
87
|
"jest": "^29.7.0",
|
|
130
|
-
"openai": "^
|
|
88
|
+
"openai": "^6.33.0",
|
|
131
89
|
"ts-jest": "^29.4.9",
|
|
132
90
|
"typescript": "^5.9.3"
|
|
133
91
|
},
|
|
@@ -159,5 +117,5 @@
|
|
|
159
117
|
"url": "https://github.com/hazeljs/hazel-js/issues"
|
|
160
118
|
},
|
|
161
119
|
"homepage": "https://hazeljs.ai",
|
|
162
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "8b7685d1250c4622f25d83992f58e13a59bb3dba"
|
|
163
121
|
}
|