@hazeljs/rag 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +192 -0
- package/README.md +504 -0
- package/dist/__tests__/graph/community-detector.test.d.ts +2 -0
- package/dist/__tests__/graph/community-detector.test.d.ts.map +1 -0
- package/dist/__tests__/graph/community-detector.test.js +87 -0
- package/dist/__tests__/graph/community-detector.test.js.map +1 -0
- package/dist/__tests__/graph/community-summarizer.test.d.ts +2 -0
- package/dist/__tests__/graph/community-summarizer.test.d.ts.map +1 -0
- package/dist/__tests__/graph/community-summarizer.test.js +131 -0
- package/dist/__tests__/graph/community-summarizer.test.js.map +1 -0
- package/dist/__tests__/graph/entity-extractor.test.d.ts +2 -0
- package/dist/__tests__/graph/entity-extractor.test.d.ts.map +1 -0
- package/dist/__tests__/graph/entity-extractor.test.js +129 -0
- package/dist/__tests__/graph/entity-extractor.test.js.map +1 -0
- package/dist/__tests__/graph/graph-rag-pipeline.test.d.ts +2 -0
- package/dist/__tests__/graph/graph-rag-pipeline.test.d.ts.map +1 -0
- package/dist/__tests__/graph/graph-rag-pipeline.test.js +158 -0
- package/dist/__tests__/graph/graph-rag-pipeline.test.js.map +1 -0
- package/dist/__tests__/graph/knowledge-graph.test.d.ts +2 -0
- package/dist/__tests__/graph/knowledge-graph.test.d.ts.map +1 -0
- package/dist/__tests__/graph/knowledge-graph.test.js +208 -0
- package/dist/__tests__/graph/knowledge-graph.test.js.map +1 -0
- package/dist/__tests__/loaders/base.loader.test.d.ts +2 -0
- package/dist/__tests__/loaders/base.loader.test.d.ts.map +1 -0
- package/dist/__tests__/loaders/base.loader.test.js +114 -0
- package/dist/__tests__/loaders/base.loader.test.js.map +1 -0
- package/dist/__tests__/loaders/csv-file.loader.test.d.ts +2 -0
- package/dist/__tests__/loaders/csv-file.loader.test.d.ts.map +1 -0
- package/dist/__tests__/loaders/csv-file.loader.test.js +98 -0
- package/dist/__tests__/loaders/csv-file.loader.test.js.map +1 -0
- package/dist/__tests__/loaders/directory.loader.test.d.ts +2 -0
- package/dist/__tests__/loaders/directory.loader.test.d.ts.map +1 -0
- package/dist/__tests__/loaders/directory.loader.test.js +154 -0
- package/dist/__tests__/loaders/directory.loader.test.js.map +1 -0
- package/dist/__tests__/loaders/html-file.loader.test.d.ts +2 -0
- package/dist/__tests__/loaders/html-file.loader.test.d.ts.map +1 -0
- package/dist/__tests__/loaders/html-file.loader.test.js +93 -0
- package/dist/__tests__/loaders/html-file.loader.test.js.map +1 -0
- package/dist/__tests__/loaders/json-file.loader.test.d.ts +2 -0
- package/dist/__tests__/loaders/json-file.loader.test.d.ts.map +1 -0
- package/dist/__tests__/loaders/json-file.loader.test.js +84 -0
- package/dist/__tests__/loaders/json-file.loader.test.js.map +1 -0
- package/dist/__tests__/loaders/markdown-file.loader.test.d.ts +2 -0
- package/dist/__tests__/loaders/markdown-file.loader.test.d.ts.map +1 -0
- package/dist/__tests__/loaders/markdown-file.loader.test.js +83 -0
- package/dist/__tests__/loaders/markdown-file.loader.test.js.map +1 -0
- package/dist/__tests__/loaders/text-file.loader.test.d.ts +2 -0
- package/dist/__tests__/loaders/text-file.loader.test.d.ts.map +1 -0
- package/dist/__tests__/loaders/text-file.loader.test.js +50 -0
- package/dist/__tests__/loaders/text-file.loader.test.js.map +1 -0
- package/dist/__tests__/rag-pipeline.test.d.ts +2 -0
- package/dist/__tests__/rag-pipeline.test.d.ts.map +1 -0
- package/dist/__tests__/rag-pipeline.test.js +210 -0
- package/dist/__tests__/rag-pipeline.test.js.map +1 -0
- package/dist/__tests__/retrieval/bm25.test.d.ts +2 -0
- package/dist/__tests__/retrieval/bm25.test.d.ts.map +1 -0
- package/dist/__tests__/retrieval/bm25.test.js +86 -0
- package/dist/__tests__/retrieval/bm25.test.js.map +1 -0
- package/dist/__tests__/retrieval/hybrid-search.test.d.ts +2 -0
- package/dist/__tests__/retrieval/hybrid-search.test.d.ts.map +1 -0
- package/dist/__tests__/retrieval/hybrid-search.test.js +85 -0
- package/dist/__tests__/retrieval/hybrid-search.test.js.map +1 -0
- package/dist/__tests__/retrieval/multi-query.test.d.ts +2 -0
- package/dist/__tests__/retrieval/multi-query.test.d.ts.map +1 -0
- package/dist/__tests__/retrieval/multi-query.test.js +90 -0
- package/dist/__tests__/retrieval/multi-query.test.js.map +1 -0
- package/dist/__tests__/text-splitters/recursive-text-splitter.test.d.ts +2 -0
- package/dist/__tests__/text-splitters/recursive-text-splitter.test.d.ts.map +1 -0
- package/dist/__tests__/text-splitters/recursive-text-splitter.test.js +97 -0
- package/dist/__tests__/text-splitters/recursive-text-splitter.test.js.map +1 -0
- package/dist/__tests__/utils/similarity.test.d.ts +2 -0
- package/dist/__tests__/utils/similarity.test.d.ts.map +1 -0
- package/dist/__tests__/utils/similarity.test.js +47 -0
- package/dist/__tests__/utils/similarity.test.js.map +1 -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 +17 -0
- package/dist/agentic/decorators/adaptive-retrieval.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/adaptive-retrieval.decorator.js +103 -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 +16 -0
- package/dist/agentic/decorators/corrective-rag.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/corrective-rag.decorator.js +142 -0
- package/dist/agentic/decorators/corrective-rag.decorator.js.map +1 -0
- package/dist/agentic/decorators/hyde.decorator.d.ts +15 -0
- package/dist/agentic/decorators/hyde.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/hyde.decorator.js +91 -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 +15 -0
- package/dist/agentic/decorators/multi-hop.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/multi-hop.decorator.js +109 -0
- package/dist/agentic/decorators/multi-hop.decorator.js.map +1 -0
- package/dist/agentic/decorators/query-planner.decorator.d.ts +20 -0
- package/dist/agentic/decorators/query-planner.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/query-planner.decorator.js +213 -0
- package/dist/agentic/decorators/query-planner.decorator.js.map +1 -0
- package/dist/agentic/decorators/query-rewriter.decorator.d.ts +16 -0
- package/dist/agentic/decorators/query-rewriter.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/query-rewriter.decorator.js +143 -0
- package/dist/agentic/decorators/query-rewriter.decorator.js.map +1 -0
- package/dist/agentic/decorators/self-reflective.decorator.d.ts +20 -0
- package/dist/agentic/decorators/self-reflective.decorator.d.ts.map +1 -0
- package/dist/agentic/decorators/self-reflective.decorator.js +189 -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 +210 -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/graph/community-detector.d.ts +45 -0
- package/dist/graph/community-detector.d.ts.map +1 -0
- package/dist/graph/community-detector.js +153 -0
- package/dist/graph/community-detector.js.map +1 -0
- package/dist/graph/community-summarizer.d.ts +41 -0
- package/dist/graph/community-summarizer.d.ts.map +1 -0
- package/dist/graph/community-summarizer.js +119 -0
- package/dist/graph/community-summarizer.js.map +1 -0
- package/dist/graph/entity-extractor.d.ts +47 -0
- package/dist/graph/entity-extractor.d.ts.map +1 -0
- package/dist/graph/entity-extractor.js +224 -0
- package/dist/graph/entity-extractor.js.map +1 -0
- package/dist/graph/graph-rag-pipeline.d.ts +83 -0
- package/dist/graph/graph-rag-pipeline.d.ts.map +1 -0
- package/dist/graph/graph-rag-pipeline.js +390 -0
- package/dist/graph/graph-rag-pipeline.js.map +1 -0
- package/dist/graph/graph.types.d.ts +186 -0
- package/dist/graph/graph.types.d.ts.map +1 -0
- package/dist/graph/graph.types.js +20 -0
- package/dist/graph/graph.types.js.map +1 -0
- package/dist/graph/index.d.ts +15 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +31 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/knowledge-graph.d.ts +57 -0
- package/dist/graph/knowledge-graph.d.ts.map +1 -0
- package/dist/graph/knowledge-graph.js +198 -0
- package/dist/graph/knowledge-graph.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/base.loader.d.ts +108 -0
- package/dist/loaders/base.loader.d.ts.map +1 -0
- package/dist/loaders/base.loader.js +123 -0
- package/dist/loaders/base.loader.js.map +1 -0
- package/dist/loaders/csv-file.loader.d.ts +61 -0
- package/dist/loaders/csv-file.loader.d.ts.map +1 -0
- package/dist/loaders/csv-file.loader.js +162 -0
- package/dist/loaders/csv-file.loader.js.map +1 -0
- package/dist/loaders/directory.loader.d.ts +67 -0
- package/dist/loaders/directory.loader.d.ts.map +1 -0
- package/dist/loaders/directory.loader.js +163 -0
- package/dist/loaders/directory.loader.js.map +1 -0
- package/dist/loaders/docx.loader.d.ts +52 -0
- package/dist/loaders/docx.loader.d.ts.map +1 -0
- package/dist/loaders/docx.loader.js +110 -0
- package/dist/loaders/docx.loader.js.map +1 -0
- package/dist/loaders/github.loader.d.ts +114 -0
- package/dist/loaders/github.loader.d.ts.map +1 -0
- package/dist/loaders/github.loader.js +217 -0
- package/dist/loaders/github.loader.js.map +1 -0
- package/dist/loaders/html-file.loader.d.ts +55 -0
- package/dist/loaders/html-file.loader.d.ts.map +1 -0
- package/dist/loaders/html-file.loader.js +170 -0
- package/dist/loaders/html-file.loader.js.map +1 -0
- package/dist/loaders/index.d.ts +52 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +61 -0
- package/dist/loaders/index.js.map +1 -0
- package/dist/loaders/json-file.loader.d.ts +51 -0
- package/dist/loaders/json-file.loader.d.ts.map +1 -0
- package/dist/loaders/json-file.loader.js +100 -0
- package/dist/loaders/json-file.loader.js.map +1 -0
- package/dist/loaders/markdown-file.loader.d.ts +61 -0
- package/dist/loaders/markdown-file.loader.d.ts.map +1 -0
- package/dist/loaders/markdown-file.loader.js +148 -0
- package/dist/loaders/markdown-file.loader.js.map +1 -0
- package/dist/loaders/pdf.loader.d.ts +64 -0
- package/dist/loaders/pdf.loader.d.ts.map +1 -0
- package/dist/loaders/pdf.loader.js +163 -0
- package/dist/loaders/pdf.loader.js.map +1 -0
- package/dist/loaders/text-file.loader.d.ts +39 -0
- package/dist/loaders/text-file.loader.d.ts.map +1 -0
- package/dist/loaders/text-file.loader.js +69 -0
- package/dist/loaders/text-file.loader.js.map +1 -0
- package/dist/loaders/web.loader.d.ts +87 -0
- package/dist/loaders/web.loader.d.ts.map +1 -0
- package/dist/loaders/web.loader.js +194 -0
- package/dist/loaders/web.loader.js.map +1 -0
- package/dist/loaders/youtube-transcript.loader.d.ts +92 -0
- package/dist/loaders/youtube-transcript.loader.d.ts.map +1 -0
- package/dist/loaders/youtube-transcript.loader.js +254 -0
- package/dist/loaders/youtube-transcript.loader.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/prompts/agentic/adaptive-retrieval.prompt.d.ts +8 -0
- package/dist/prompts/agentic/adaptive-retrieval.prompt.d.ts.map +1 -0
- package/dist/prompts/agentic/adaptive-retrieval.prompt.js +27 -0
- package/dist/prompts/agentic/adaptive-retrieval.prompt.js.map +1 -0
- package/dist/prompts/agentic/corrective-rag.prompt.d.ts +9 -0
- package/dist/prompts/agentic/corrective-rag.prompt.d.ts.map +1 -0
- package/dist/prompts/agentic/corrective-rag.prompt.js +23 -0
- package/dist/prompts/agentic/corrective-rag.prompt.js.map +1 -0
- package/dist/prompts/agentic/hyde.prompt.d.ts +9 -0
- package/dist/prompts/agentic/hyde.prompt.d.ts.map +1 -0
- package/dist/prompts/agentic/hyde.prompt.js +18 -0
- package/dist/prompts/agentic/hyde.prompt.js.map +1 -0
- package/dist/prompts/agentic/multi-hop.prompt.d.ts +15 -0
- package/dist/prompts/agentic/multi-hop.prompt.d.ts.map +1 -0
- package/dist/prompts/agentic/multi-hop.prompt.js +38 -0
- package/dist/prompts/agentic/multi-hop.prompt.js.map +1 -0
- package/dist/prompts/agentic/query-planner.prompt.d.ts +8 -0
- package/dist/prompts/agentic/query-planner.prompt.d.ts.map +1 -0
- package/dist/prompts/agentic/query-planner.prompt.js +30 -0
- package/dist/prompts/agentic/query-planner.prompt.js.map +1 -0
- package/dist/prompts/agentic/query-rewriter.prompt.d.ts +10 -0
- package/dist/prompts/agentic/query-rewriter.prompt.d.ts.map +1 -0
- package/dist/prompts/agentic/query-rewriter.prompt.js +17 -0
- package/dist/prompts/agentic/query-rewriter.prompt.js.map +1 -0
- package/dist/prompts/agentic/self-reflective-improve.prompt.d.ts +10 -0
- package/dist/prompts/agentic/self-reflective-improve.prompt.d.ts.map +1 -0
- package/dist/prompts/agentic/self-reflective-improve.prompt.js +24 -0
- package/dist/prompts/agentic/self-reflective-improve.prompt.js.map +1 -0
- package/dist/prompts/agentic/self-reflective.prompt.d.ts +9 -0
- package/dist/prompts/agentic/self-reflective.prompt.d.ts.map +1 -0
- package/dist/prompts/agentic/self-reflective.prompt.js +32 -0
- package/dist/prompts/agentic/self-reflective.prompt.js.map +1 -0
- package/dist/prompts/community-summary.prompt.d.ts +9 -0
- package/dist/prompts/community-summary.prompt.d.ts.map +1 -0
- package/dist/prompts/community-summary.prompt.js +30 -0
- package/dist/prompts/community-summary.prompt.js.map +1 -0
- package/dist/prompts/entity-extraction.prompt.d.ts +10 -0
- package/dist/prompts/entity-extraction.prompt.d.ts.map +1 -0
- package/dist/prompts/entity-extraction.prompt.js +39 -0
- package/dist/prompts/entity-extraction.prompt.js.map +1 -0
- package/dist/prompts/graph-search.prompt.d.ts +10 -0
- package/dist/prompts/graph-search.prompt.d.ts.map +1 -0
- package/dist/prompts/graph-search.prompt.js +23 -0
- package/dist/prompts/graph-search.prompt.js.map +1 -0
- package/dist/prompts/index.d.ts +13 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +29 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/rag-answer.prompt.d.ts +9 -0
- package/dist/prompts/rag-answer.prompt.d.ts.map +1 -0
- package/dist/prompts/rag-answer.prompt.js +20 -0
- package/dist/prompts/rag-answer.prompt.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 +96 -0
- package/dist/rag.service.d.ts.map +1 -0
- package/dist/rag.service.js +173 -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 +33 -0
- package/dist/vector-stores/qdrant.store.d.ts.map +1 -0
- package/dist/vector-stores/qdrant.store.js +174 -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 +146 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2024 HazelJS Team
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
+
|
|
23
|
+
1. Definitions.
|
|
24
|
+
|
|
25
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
26
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
27
|
+
|
|
28
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
29
|
+
the copyright owner that is granting the License.
|
|
30
|
+
|
|
31
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
32
|
+
other entities that control, are controlled by, or are under common
|
|
33
|
+
control with that entity. For the purposes of this definition,
|
|
34
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
35
|
+
direction or management of such entity, whether by contract or
|
|
36
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
37
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
38
|
+
|
|
39
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
40
|
+
exercising permissions granted by this License.
|
|
41
|
+
|
|
42
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
43
|
+
including but not limited to software source code, documentation
|
|
44
|
+
source, and configuration files.
|
|
45
|
+
|
|
46
|
+
"Object" form shall mean any form resulting from mechanical
|
|
47
|
+
transformation or translation of a Source form, including but
|
|
48
|
+
not limited to compiled object code, generated documentation,
|
|
49
|
+
and conversions to other media types.
|
|
50
|
+
|
|
51
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
52
|
+
Object form, made available under the License, as indicated by a
|
|
53
|
+
copyright notice that is included in or attached to the work
|
|
54
|
+
(an example is provided in the Appendix below).
|
|
55
|
+
|
|
56
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
57
|
+
form, that is based on (or derived from) the Work and for which the
|
|
58
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
59
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
60
|
+
of this License, Derivative Works shall not include works that remain
|
|
61
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
62
|
+
the Work and Derivative Works thereof.
|
|
63
|
+
|
|
64
|
+
"Contribution" shall mean any work of authorship, including
|
|
65
|
+
the original version of the Work and any modifications or additions
|
|
66
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
67
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
68
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
69
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
70
|
+
means any form of electronic, verbal, or written communication sent
|
|
71
|
+
to the Licensor or its representatives, including but not limited to
|
|
72
|
+
communication on electronic mailing lists, source code control systems,
|
|
73
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
74
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
75
|
+
excluding communication that is conspicuously marked or otherwise
|
|
76
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
77
|
+
|
|
78
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
79
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
80
|
+
subsequently incorporated within the Work.
|
|
81
|
+
|
|
82
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
86
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
87
|
+
Work and such Derivative Works in Source or Object form.
|
|
88
|
+
|
|
89
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
90
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
91
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
92
|
+
(except as stated in this section) patent license to make, have made,
|
|
93
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
94
|
+
where such license applies only to those patent claims licensable
|
|
95
|
+
by such Contributor that are necessarily infringed by their
|
|
96
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
97
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
98
|
+
institute patent litigation against any entity (including a
|
|
99
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
100
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
101
|
+
or contributory patent infringement, then any patent licenses
|
|
102
|
+
granted to You under this License for that Work shall terminate
|
|
103
|
+
as of the date such litigation is filed.
|
|
104
|
+
|
|
105
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
106
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
107
|
+
modifications, and in Source or Object form, provided that You
|
|
108
|
+
meet the following conditions:
|
|
109
|
+
|
|
110
|
+
(a) You must give any other recipients of the Work or
|
|
111
|
+
Derivative Works a copy of this License; and
|
|
112
|
+
|
|
113
|
+
(b) You must cause any modified files to carry prominent notices
|
|
114
|
+
stating that You changed the files; and
|
|
115
|
+
|
|
116
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
117
|
+
that You distribute, all copyright, patent, trademark, and
|
|
118
|
+
attribution notices from the Source form of the Work,
|
|
119
|
+
excluding those notices that do not pertain to any part of
|
|
120
|
+
the Derivative Works; and
|
|
121
|
+
|
|
122
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
123
|
+
distribution, then any Derivative Works that You distribute must
|
|
124
|
+
include a readable copy of the attribution notices contained
|
|
125
|
+
within such NOTICE file, excluding those notices that do not
|
|
126
|
+
pertain to any part of the Derivative Works, in at least one
|
|
127
|
+
of the following places: within a NOTICE text file distributed
|
|
128
|
+
as part of the Derivative Works; within the Source form or
|
|
129
|
+
documentation, if provided along with the Derivative Works; or,
|
|
130
|
+
within a display generated by the Derivative Works, if and
|
|
131
|
+
wherever such third-party notices normally appear. The contents
|
|
132
|
+
of the NOTICE file are for informational purposes only and
|
|
133
|
+
do not modify the License. You may add Your own attribution
|
|
134
|
+
notices within Derivative Works that You distribute, alongside
|
|
135
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
136
|
+
that such additional attribution notices cannot be construed
|
|
137
|
+
as modifying the License.
|
|
138
|
+
|
|
139
|
+
You may add Your own copyright statement to Your modifications and
|
|
140
|
+
may provide additional or different license terms and conditions
|
|
141
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
142
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
143
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
144
|
+
the conditions stated in this License.
|
|
145
|
+
|
|
146
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
147
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
148
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
149
|
+
this License, without any additional terms or conditions.
|
|
150
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
151
|
+
the terms of any separate license agreement you may have executed
|
|
152
|
+
with Licensor regarding such Contributions.
|
|
153
|
+
|
|
154
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
155
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
156
|
+
except as required for reasonable and customary use in describing the
|
|
157
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
158
|
+
|
|
159
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
160
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
161
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
162
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
163
|
+
implied, including, without limitation, any warranties or conditions
|
|
164
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
165
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
166
|
+
appropriateness of using or redistributing the Work and assume any
|
|
167
|
+
risks associated with Your exercise of permissions under this License.
|
|
168
|
+
|
|
169
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
170
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
171
|
+
unless required by applicable law (such as deliberate and grossly
|
|
172
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
173
|
+
liable to You for damages, including any direct, indirect, special,
|
|
174
|
+
incidental, or consequential damages of any character arising as a
|
|
175
|
+
result of this License or out of the use or inability to use the
|
|
176
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
177
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
178
|
+
other commercial damages or losses), even if such Contributor
|
|
179
|
+
has been advised of the possibility of such damages.
|
|
180
|
+
|
|
181
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
182
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
183
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
184
|
+
or other liability obligations and/or rights consistent with this
|
|
185
|
+
License. However, in accepting such obligations, You may act only
|
|
186
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
187
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
188
|
+
defend, and hold each Contributor harmless for any liability
|
|
189
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
190
|
+
of your accepting any such warranty or additional liability.
|
|
191
|
+
|
|
192
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
# @hazeljs/rag
|
|
2
|
+
|
|
3
|
+
**Your docs. Your data. AI that actually knows them.**
|
|
4
|
+
|
|
5
|
+
Load documents from any source, build a knowledge graph, embed into vector stores, and retrieve answers with semantic, hybrid, or graph-based search. Full RAG + GraphRAG pipeline β no PhD required.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@hazeljs/rag)
|
|
8
|
+
[](https://www.npmjs.com/package/@hazeljs/rag)
|
|
9
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- π **11 Document Loaders** β TXT, Markdown, JSON, CSV, HTML, PDF, DOCX, web scraping, YouTube transcripts, GitHub repos, and inline text. All return the same `Document[]` interface.
|
|
14
|
+
- πΈοΈ **GraphRAG** β Extract entities and relationships from documents, build a knowledge graph, detect communities, and answer questions with entity-centric (local), thematic (global), or hybrid search.
|
|
15
|
+
- π **Vector Search** β Semantic similarity search with configurable embeddings and vector stores
|
|
16
|
+
- π€ **RAG Pipeline** β Complete load β split β embed β retrieve β augment workflow
|
|
17
|
+
- π― **Multiple Strategies** β Similarity, Hybrid (vector + BM25), Multi-Query retrieval
|
|
18
|
+
- π **5 Vector Stores** β Memory, Pinecone, Qdrant, Weaviate, ChromaDB (unified interface)
|
|
19
|
+
- π **Embedding Providers** β OpenAI and Cohere, easily extensible
|
|
20
|
+
- βοΈ **Smart Text Splitting** β Recursive, character, and token splitters
|
|
21
|
+
- π **Metadata Filtering** β Filter results by any metadata field
|
|
22
|
+
- π§ **Memory System** β Conversation history, entity memory, fact storage, working memory
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @hazeljs/rag
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Optional peer dependencies
|
|
33
|
+
|
|
34
|
+
Install only what you need:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# LLM (required for GraphRAG and RAG query synthesis)
|
|
38
|
+
npm install openai
|
|
39
|
+
|
|
40
|
+
# Vector stores
|
|
41
|
+
npm install @pinecone-database/pinecone # Pinecone
|
|
42
|
+
npm install @qdrant/js-client-rest # Qdrant
|
|
43
|
+
npm install weaviate-ts-client # Weaviate
|
|
44
|
+
npm install chromadb # ChromaDB
|
|
45
|
+
|
|
46
|
+
# Alternative embedding providers
|
|
47
|
+
npm install cohere-ai
|
|
48
|
+
|
|
49
|
+
# Document loaders
|
|
50
|
+
npm install pdf-parse # PdfLoader
|
|
51
|
+
npm install mammoth # DocxLoader
|
|
52
|
+
npm install cheerio # HtmlFileLoader / WebLoader CSS selectors
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
### Basic RAG pipeline
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import {
|
|
63
|
+
RAGPipeline,
|
|
64
|
+
MemoryVectorStore,
|
|
65
|
+
OpenAIEmbeddings,
|
|
66
|
+
RecursiveTextSplitter,
|
|
67
|
+
DirectoryLoader,
|
|
68
|
+
} from '@hazeljs/rag';
|
|
69
|
+
|
|
70
|
+
const embeddings = new OpenAIEmbeddings({ apiKey: process.env.OPENAI_API_KEY });
|
|
71
|
+
const vectorStore = new MemoryVectorStore(embeddings);
|
|
72
|
+
|
|
73
|
+
const rag = new RAGPipeline({
|
|
74
|
+
vectorStore,
|
|
75
|
+
embeddingProvider: embeddings,
|
|
76
|
+
textSplitter: new RecursiveTextSplitter({ chunkSize: 800, chunkOverlap: 150 }),
|
|
77
|
+
topK: 5,
|
|
78
|
+
});
|
|
79
|
+
await rag.initialize();
|
|
80
|
+
|
|
81
|
+
// Load from disk β auto-detects file types
|
|
82
|
+
const docs = await new DirectoryLoader({ dirPath: './knowledge-base', recursive: true }).load();
|
|
83
|
+
await rag.addDocuments(docs);
|
|
84
|
+
|
|
85
|
+
const result = await rag.query('What is HazelJS?', { topK: 3 });
|
|
86
|
+
console.log(result.answer);
|
|
87
|
+
console.log(result.sources);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Document Loaders
|
|
93
|
+
|
|
94
|
+
Every loader extends `BaseDocumentLoader` and returns `Document[]` ready for chunking and indexing.
|
|
95
|
+
|
|
96
|
+
### Built-in loaders
|
|
97
|
+
|
|
98
|
+
| Loader | Source | Extra install |
|
|
99
|
+
|--------|--------|:---:|
|
|
100
|
+
| `TextFileLoader` | `.txt` files | β |
|
|
101
|
+
| `MarkdownFileLoader` | `.md` / `.mdx` with heading splits and YAML front-matter | β |
|
|
102
|
+
| `JSONFileLoader` | `.json` with `textKey` / JSON Pointer extraction | β |
|
|
103
|
+
| `CSVFileLoader` | `.csv` rows mapped to documents | β |
|
|
104
|
+
| `HtmlFileLoader` | `.html` tag stripping; optional CSS selector via cheerio | opt. |
|
|
105
|
+
| `DirectoryLoader` | Recursive walk; auto-detects loader by extension | β |
|
|
106
|
+
| `PdfLoader` | PDFs; split by page or full document | `pdf-parse` |
|
|
107
|
+
| `DocxLoader` | Word documents; plain text or HTML output | `mammoth` |
|
|
108
|
+
| `WebLoader` | HTTP scraping with retry/timeout; optional CSS selector | opt. |
|
|
109
|
+
| `YouTubeTranscriptLoader` | YouTube transcripts; no API key; segment by duration | β |
|
|
110
|
+
| `GitHubLoader` | GitHub REST API; filter by path, extension, `maxFiles` | β |
|
|
111
|
+
|
|
112
|
+
### Examples
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import {
|
|
116
|
+
TextFileLoader,
|
|
117
|
+
MarkdownFileLoader,
|
|
118
|
+
JSONFileLoader,
|
|
119
|
+
CSVFileLoader,
|
|
120
|
+
PdfLoader,
|
|
121
|
+
DocxLoader,
|
|
122
|
+
WebLoader,
|
|
123
|
+
YouTubeTranscriptLoader,
|
|
124
|
+
GitHubLoader,
|
|
125
|
+
DirectoryLoader,
|
|
126
|
+
} from '@hazeljs/rag';
|
|
127
|
+
|
|
128
|
+
// Plain text
|
|
129
|
+
const textDocs = await new TextFileLoader({ filePath: './notes.txt' }).load();
|
|
130
|
+
|
|
131
|
+
// Markdown β one document per heading section
|
|
132
|
+
const mdDocs = await new MarkdownFileLoader({
|
|
133
|
+
filePath: './guide.md',
|
|
134
|
+
splitByHeading: true,
|
|
135
|
+
parseYamlFrontMatter: true,
|
|
136
|
+
}).load();
|
|
137
|
+
|
|
138
|
+
// JSON β extract the 'body' field from each element
|
|
139
|
+
const jsonDocs = await new JSONFileLoader({ filePath: './articles.json', textKey: 'body' }).load();
|
|
140
|
+
|
|
141
|
+
// CSV β map columns to content / metadata
|
|
142
|
+
const csvDocs = await new CSVFileLoader({
|
|
143
|
+
filePath: './faqs.csv',
|
|
144
|
+
contentColumns: ['question', 'answer'],
|
|
145
|
+
metadataColumns: ['category'],
|
|
146
|
+
}).load();
|
|
147
|
+
|
|
148
|
+
// PDF β one document per page
|
|
149
|
+
const pdfDocs = await new PdfLoader({ filePath: './report.pdf', splitByPage: true }).load();
|
|
150
|
+
|
|
151
|
+
// DOCX
|
|
152
|
+
const wordDocs = await new DocxLoader({ filePath: './agreement.docx' }).load();
|
|
153
|
+
|
|
154
|
+
// Web scraping
|
|
155
|
+
const webDocs = await new WebLoader({
|
|
156
|
+
urls: ['https://hazeljs.com/docs', 'https://hazeljs.com/blog'],
|
|
157
|
+
timeout: 10_000,
|
|
158
|
+
maxRetries: 3,
|
|
159
|
+
}).load();
|
|
160
|
+
|
|
161
|
+
// YouTube transcript (no API key needed)
|
|
162
|
+
const ytDocs = await new YouTubeTranscriptLoader({
|
|
163
|
+
videoUrl: 'https://www.youtube.com/watch?v=VIDEO_ID',
|
|
164
|
+
segmentDuration: 60, // group into 60-second chunks
|
|
165
|
+
}).load();
|
|
166
|
+
|
|
167
|
+
// GitHub repository
|
|
168
|
+
const githubDocs = await new GitHubLoader({
|
|
169
|
+
owner: 'hazeljs',
|
|
170
|
+
repo: 'hazel',
|
|
171
|
+
directory: 'docs',
|
|
172
|
+
extensions: ['.md'],
|
|
173
|
+
token: process.env.GITHUB_TOKEN,
|
|
174
|
+
}).load();
|
|
175
|
+
|
|
176
|
+
// Directory β auto-detects every file type
|
|
177
|
+
const allDocs = await new DirectoryLoader({
|
|
178
|
+
dirPath: './knowledge-base',
|
|
179
|
+
recursive: true,
|
|
180
|
+
extensions: ['.md', '.txt', '.pdf'],
|
|
181
|
+
}).load();
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Custom loaders
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { BaseDocumentLoader, Loader, DocumentLoaderRegistry } from '@hazeljs/rag';
|
|
188
|
+
|
|
189
|
+
@Loader({ name: 'NotionLoader', extensions: [] })
|
|
190
|
+
export class NotionLoader extends BaseDocumentLoader {
|
|
191
|
+
constructor(private readonly databaseId: string) { super(); }
|
|
192
|
+
|
|
193
|
+
async load() {
|
|
194
|
+
const pages = await fetchNotionPages(this.databaseId);
|
|
195
|
+
return pages.map(p =>
|
|
196
|
+
this.createDocument(p.content, { source: `notion:${p.id}`, title: p.title }),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Register so DirectoryLoader can auto-detect it
|
|
202
|
+
DocumentLoaderRegistry.register(NotionLoader, (id: string) => new NotionLoader(id));
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## GraphRAG
|
|
208
|
+
|
|
209
|
+
GraphRAG builds a **knowledge graph** from your documents β entities, relationships, and community clusters β and enables three complementary search modes that go far beyond cosine similarity.
|
|
210
|
+
|
|
211
|
+
### Why GraphRAG?
|
|
212
|
+
|
|
213
|
+
| Question type | Traditional RAG | GraphRAG |
|
|
214
|
+
|---|---|---|
|
|
215
|
+
| "What does X do?" | β
Good | β
Excellent (entity traversal) |
|
|
216
|
+
| "How do X and Y relate?" | β Poor | β
Excellent (relationships) |
|
|
217
|
+
| "What are the main architectural layers?" | β Poor | β
Excellent (community reports) |
|
|
218
|
+
| Multi-document cross-referencing | β Fragmented | β
Native |
|
|
219
|
+
|
|
220
|
+
### Build the graph
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import OpenAI from 'openai';
|
|
224
|
+
import { GraphRAGPipeline, DirectoryLoader } from '@hazeljs/rag';
|
|
225
|
+
|
|
226
|
+
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
227
|
+
|
|
228
|
+
const graphRag = new GraphRAGPipeline({
|
|
229
|
+
// Provider-agnostic: any LLM that accepts a string prompt
|
|
230
|
+
llm: async (prompt) => {
|
|
231
|
+
const res = await openai.chat.completions.create({
|
|
232
|
+
model: 'gpt-4o-mini',
|
|
233
|
+
temperature: 0,
|
|
234
|
+
messages: [{ role: 'user', content: prompt }],
|
|
235
|
+
});
|
|
236
|
+
return res.choices[0].message.content ?? '';
|
|
237
|
+
},
|
|
238
|
+
extractionChunkSize: 2000, // chars per LLM extraction call
|
|
239
|
+
generateCommunityReports: true, // LLM summaries per community cluster
|
|
240
|
+
maxCommunitySize: 15, // split clusters larger than this
|
|
241
|
+
localSearchDepth: 2, // BFS hops for local search
|
|
242
|
+
localSearchTopK: 5, // seed entities per query
|
|
243
|
+
globalSearchTopK: 5, // community reports for global search
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const docs = await new DirectoryLoader({ dirPath: './knowledge-base', recursive: true }).load();
|
|
247
|
+
const stats = await graphRag.build(docs);
|
|
248
|
+
// { documentsProcessed, entitiesExtracted, relationshipsExtracted,
|
|
249
|
+
// communitiesDetected, communityReportsGenerated, duration }
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Search modes
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
// LOCAL β entity-centric, BFS graph traversal
|
|
256
|
+
// Best for: specific questions about named concepts, classes, or technologies
|
|
257
|
+
const local = await graphRag.search(
|
|
258
|
+
'How does dependency injection work?',
|
|
259
|
+
{ mode: 'local' },
|
|
260
|
+
);
|
|
261
|
+
console.log(local.answer);
|
|
262
|
+
console.log(local.entities); // entities found and traversed
|
|
263
|
+
console.log(local.relationships); // evidence relationships
|
|
264
|
+
|
|
265
|
+
// GLOBAL β community report ranking
|
|
266
|
+
// Best for: broad thematic questions, architecture overviews
|
|
267
|
+
const global = await graphRag.search(
|
|
268
|
+
'What are the main architectural layers of this system?',
|
|
269
|
+
{ mode: 'global' },
|
|
270
|
+
);
|
|
271
|
+
console.log(global.communities); // ranked community reports used
|
|
272
|
+
|
|
273
|
+
// HYBRID β runs both in parallel, single synthesis call (recommended default)
|
|
274
|
+
const result = await graphRag.search('What vector stores does @hazeljs/rag support?');
|
|
275
|
+
// mode defaults to 'hybrid'
|
|
276
|
+
console.log(`${result.mode} search in ${result.duration}ms`);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Incremental updates
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
const newDocs = await new WebLoader({ urls: ['https://hazeljs.com/blog/new'] }).load();
|
|
283
|
+
await graphRag.addDocuments(newDocs);
|
|
284
|
+
// Re-runs community detection and regenerates reports automatically
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Inspect the graph
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
const graph = graphRag.getGraph();
|
|
291
|
+
|
|
292
|
+
// Entities, relationships, community reports
|
|
293
|
+
console.log([...graph.entities.values()].slice(0, 5));
|
|
294
|
+
console.log([...graph.relationships.values()].slice(0, 5));
|
|
295
|
+
console.log([...graph.communityReports.values()].map(r => r.title));
|
|
296
|
+
|
|
297
|
+
// Statistics
|
|
298
|
+
const stats = graphRag.getStats();
|
|
299
|
+
console.log(stats.entityTypeBreakdown); // { TECHNOLOGY: 14, CONCEPT: 12, ... }
|
|
300
|
+
console.log(stats.topEntities.slice(0, 5)); // most-connected entities
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Vector Stores
|
|
306
|
+
|
|
307
|
+
All stores implement the same interface β swap them with a one-line change.
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
import { MemoryVectorStore, OpenAIEmbeddings } from '@hazeljs/rag';
|
|
311
|
+
|
|
312
|
+
// Development
|
|
313
|
+
const vectorStore = new MemoryVectorStore(embeddings);
|
|
314
|
+
|
|
315
|
+
// Pinecone (production, serverless)
|
|
316
|
+
import { PineconeVectorStore } from '@hazeljs/rag';
|
|
317
|
+
const vectorStore = new PineconeVectorStore(embeddings, {
|
|
318
|
+
apiKey: process.env.PINECONE_API_KEY,
|
|
319
|
+
indexName: 'my-knowledge-base',
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Qdrant (high-performance, self-hosted)
|
|
323
|
+
import { QdrantVectorStore } from '@hazeljs/rag';
|
|
324
|
+
const vectorStore = new QdrantVectorStore(embeddings, {
|
|
325
|
+
url: process.env.QDRANT_URL || 'http://localhost:6333',
|
|
326
|
+
collectionName: 'my-collection',
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Weaviate (GraphQL, flexible)
|
|
330
|
+
import { WeaviateVectorStore } from '@hazeljs/rag';
|
|
331
|
+
const vectorStore = new WeaviateVectorStore(embeddings, {
|
|
332
|
+
host: process.env.WEAVIATE_HOST || 'http://localhost:8080',
|
|
333
|
+
className: 'MyKnowledgeBase',
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// ChromaDB (prototyping)
|
|
337
|
+
import { ChromaVectorStore } from '@hazeljs/rag';
|
|
338
|
+
const vectorStore = new ChromaVectorStore(embeddings, {
|
|
339
|
+
url: process.env.CHROMA_URL || 'http://localhost:8000',
|
|
340
|
+
collectionName: 'my-collection',
|
|
341
|
+
});
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Vector store comparison
|
|
345
|
+
|
|
346
|
+
| | Memory | Pinecone | Qdrant | Weaviate | ChromaDB |
|
|
347
|
+
|---|:---:|:---:|:---:|:---:|:---:|
|
|
348
|
+
| Setup | None | API Key | Docker | Docker | Docker |
|
|
349
|
+
| Persistence | β | β
| β
| β
| β
|
|
|
350
|
+
| Best for | Dev/Test | Production | High-perf | GraphQL | Prototyping |
|
|
351
|
+
| Cost | Free | Paid | OSS | OSS | OSS |
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## Embedding Providers
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
import { OpenAIEmbeddings, CohereEmbeddings } from '@hazeljs/rag';
|
|
359
|
+
|
|
360
|
+
// OpenAI
|
|
361
|
+
const openaiEmbed = new OpenAIEmbeddings({
|
|
362
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
363
|
+
model: 'text-embedding-3-small', // 1536 dims
|
|
364
|
+
// model: 'text-embedding-3-large', // 3072 dims, highest quality
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// Cohere (multilingual)
|
|
368
|
+
const cohereEmbed = new CohereEmbeddings({
|
|
369
|
+
apiKey: process.env.COHERE_API_KEY,
|
|
370
|
+
model: 'embed-multilingual-v3.0',
|
|
371
|
+
});
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## Retrieval Strategies
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import { HybridSearchRetrieval, MultiQueryRetrieval } from '@hazeljs/rag';
|
|
380
|
+
|
|
381
|
+
// Hybrid β vector + BM25 keyword fusion
|
|
382
|
+
const hybrid = new HybridSearchRetrieval(vectorStore, {
|
|
383
|
+
vectorWeight: 0.7,
|
|
384
|
+
keywordWeight: 0.3,
|
|
385
|
+
topK: 10,
|
|
386
|
+
});
|
|
387
|
+
const results = await hybrid.search('machine learning algorithms', { topK: 5 });
|
|
388
|
+
|
|
389
|
+
// Multi-query β LLM generates N query variations, deduplicates results
|
|
390
|
+
const multiQuery = new MultiQueryRetrieval(vectorStore, {
|
|
391
|
+
llmApiKey: process.env.OPENAI_API_KEY,
|
|
392
|
+
numQueries: 3,
|
|
393
|
+
topK: 10,
|
|
394
|
+
});
|
|
395
|
+
const results2 = await multiQuery.search('How do I deploy my app?', { topK: 5 });
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## Text Splitting
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
import { RecursiveTextSplitter } from '@hazeljs/rag';
|
|
404
|
+
|
|
405
|
+
const splitter = new RecursiveTextSplitter({
|
|
406
|
+
chunkSize: 1000, // target chars per chunk
|
|
407
|
+
chunkOverlap: 200, // overlap for context continuity
|
|
408
|
+
separators: ['\n\n', '\n', '. ', ' '],
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const chunks = splitter.split(longDocument);
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## Memory System
|
|
417
|
+
|
|
418
|
+
```typescript
|
|
419
|
+
import {
|
|
420
|
+
RAGPipelineWithMemory,
|
|
421
|
+
MemoryManager,
|
|
422
|
+
HybridMemory,
|
|
423
|
+
BufferMemory,
|
|
424
|
+
VectorMemory,
|
|
425
|
+
} from '@hazeljs/rag';
|
|
426
|
+
|
|
427
|
+
const buffer = new BufferMemory({ maxSize: 20 });
|
|
428
|
+
const vectorMemory = new VectorMemory(vectorStore, embeddings);
|
|
429
|
+
const memory = new MemoryManager(new HybridMemory(buffer, vectorMemory));
|
|
430
|
+
|
|
431
|
+
const rag = new RAGPipelineWithMemory(config, memory, llmFunction);
|
|
432
|
+
|
|
433
|
+
const response = await rag.queryWithMemory(
|
|
434
|
+
'What did we discuss about deployment?',
|
|
435
|
+
'session-123',
|
|
436
|
+
'user-456',
|
|
437
|
+
);
|
|
438
|
+
console.log(response.answer);
|
|
439
|
+
console.log(response.memories);
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
## API Reference
|
|
445
|
+
|
|
446
|
+
### `GraphRAGPipeline`
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
class GraphRAGPipeline {
|
|
450
|
+
constructor(config: GraphRAGConfig);
|
|
451
|
+
build(docs: Document[]): Promise<GraphBuildStats>;
|
|
452
|
+
addDocuments(docs: Document[]): Promise<GraphBuildStats>;
|
|
453
|
+
search(query: string, options?: GraphSearchOptions): Promise<GraphSearchResult>;
|
|
454
|
+
getGraph(): KnowledgeGraph;
|
|
455
|
+
getStats(): GraphStats;
|
|
456
|
+
clear(): void;
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### `RAGPipeline`
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
class RAGPipeline {
|
|
464
|
+
constructor(config: RAGConfig, llmFunction?: LLMFunction);
|
|
465
|
+
initialize(): Promise<void>;
|
|
466
|
+
addDocuments(documents: Document[]): Promise<string[]>;
|
|
467
|
+
query(query: string, options?: RAGQueryOptions): Promise<RAGResponse>;
|
|
468
|
+
search(query: string, options?: QueryOptions): Promise<SearchResult[]>;
|
|
469
|
+
deleteDocuments(ids: string[]): Promise<void>;
|
|
470
|
+
clear(): Promise<void>;
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
### `Document`
|
|
475
|
+
|
|
476
|
+
```typescript
|
|
477
|
+
interface Document {
|
|
478
|
+
id?: string;
|
|
479
|
+
content: string;
|
|
480
|
+
metadata?: Record<string, unknown>;
|
|
481
|
+
embedding?: number[];
|
|
482
|
+
}
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
---
|
|
486
|
+
|
|
487
|
+
## Use Cases
|
|
488
|
+
|
|
489
|
+
- π **Documentation Q&A** β Index all your docs and answer developer questions
|
|
490
|
+
- πΈοΈ **Codebase Understanding** β GraphRAG over a repo to explain architecture and dependencies
|
|
491
|
+
- π¬ **Context-Aware Chatbots** β RAG + memory for multi-turn conversations
|
|
492
|
+
- π **Enterprise Knowledge Base** β Combine web, GitHub, PDFs, and internal wikis
|
|
493
|
+
- π **Research Assistants** β Multi-document reasoning with knowledge graph traversal
|
|
494
|
+
- π **Content Intelligence** β Semantic search + relationship mapping across articles
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## License
|
|
499
|
+
|
|
500
|
+
Apache 2.0
|
|
501
|
+
|
|
502
|
+
## Contributing
|
|
503
|
+
|
|
504
|
+
Contributions are welcome! See [CONTRIBUTING.md](../../CONTRIBUTING.md) for details.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"community-detector.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/graph/community-detector.test.ts"],"names":[],"mappings":""}
|