@retrivora-ai/rag-engine 0.4.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -57
- package/dist/{ChromaDBProvider-GI7TB7GJ.mjs → ChromaDBProvider-APQVJ5F7.mjs} +2 -2
- package/dist/{DocumentChunker-3yElxTO3.d.mts → DocumentChunker-C-sCZPhi.d.mts} +6 -6
- package/dist/{DocumentChunker-3yElxTO3.d.ts → DocumentChunker-C-sCZPhi.d.ts} +6 -6
- package/dist/{MilvusProvider-WDVTFB7D.mjs → MilvusProvider-35US67MS.mjs} +2 -2
- package/dist/{MongoDBProvider-RE3Q5S5B.mjs → MongoDBProvider-COVYZDP6.mjs} +2 -2
- package/dist/{PineconeProvider-BE2JWSPD.mjs → PineconeProvider-AWFJQDZL.mjs} +2 -2
- package/dist/{PostgreSQLProvider-5HHTK4SU.mjs → PostgreSQLProvider-IEYRJ7XJ.mjs} +2 -2
- package/dist/{QdrantProvider-XVDVBNIG.mjs → QdrantProvider-M6TQYZRO.mjs} +2 -2
- package/dist/{RagConfig-BgRDL9Vy.d.mts → RagConfig-DRJO4hGU.d.mts} +12 -1
- package/dist/{RagConfig-BgRDL9Vy.d.ts → RagConfig-DRJO4hGU.d.ts} +12 -1
- package/dist/{RedisProvider-EK2R2PQH.mjs → RedisProvider-3G5PBLZ4.mjs} +2 -2
- package/dist/{SimpleGraphProvider-M6T7SE7D.mjs → SimpleGraphProvider-UK7DJW37.mjs} +1 -1
- package/dist/{UniversalVectorProvider-YIDRX6VT.mjs → UniversalVectorProvider-FYQ3B2PW.mjs} +3 -3
- package/dist/{WeaviateProvider-4CAPQ7UY.mjs → WeaviateProvider-ITHO36IL.mjs} +2 -2
- package/dist/{chunk-5KNBWQM6.mjs → chunk-4A47RCG2.mjs} +5 -1
- package/dist/{chunk-EDLTMSNY.mjs → chunk-67AJ6SMD.mjs} +1 -1
- package/dist/{chunk-PQKTC73Y.mjs → chunk-7SOSCZGS.mjs} +67 -6
- package/dist/{chunk-LJWWPTWE.mjs → chunk-FLOSGE6A.mjs} +76 -14
- package/dist/{chunk-H6RKMU7W.mjs → chunk-NXUCKY5L.mjs} +1 -1
- package/dist/{chunk-KTS3LLHY.mjs → chunk-OOQXNLXD.mjs} +5 -5
- package/dist/{chunk-PRC5CZIZ.mjs → chunk-P4HAQ7KB.mjs} +1184 -1359
- package/dist/chunk-QMIKLALV.mjs +57 -0
- package/dist/{chunk-3QWAK3RZ.mjs → chunk-TYHTZIDP.mjs} +6 -2
- package/dist/{chunk-GQT5LF4G.mjs → chunk-U6KHVZLF.mjs} +2 -2
- package/dist/{chunk-RK2UDJA2.mjs → chunk-WGSZNY3X.mjs} +1 -1
- package/dist/{chunk-XCNXPECE.mjs → chunk-ZNBKHNJ4.mjs} +55 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +1415 -1391
- package/dist/handlers/index.mjs +3 -3
- package/dist/index-CrGMwXfO.d.ts +112 -0
- package/dist/index-v669iV-k.d.mts +112 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/server.d.mts +104 -158
- package/dist/server.d.ts +104 -158
- package/dist/server.js +1414 -1390
- package/dist/server.mjs +12 -12
- package/package.json +5 -1
- package/src/config/RagConfig.ts +7 -0
- package/src/core/ConfigValidator.ts +66 -492
- package/src/core/LangChainAgent.ts +78 -0
- package/src/core/Pipeline.ts +210 -240
- package/src/core/ProviderHealthCheck.ts +35 -406
- package/src/core/ProviderInterfaces.ts +37 -0
- package/src/core/ProviderRegistry.ts +70 -55
- package/src/core/QueryProcessor.ts +173 -0
- package/src/llm/ILLMProvider.ts +10 -0
- package/src/llm/LLMFactory.ts +33 -13
- package/src/llm/providers/AnthropicProvider.ts +55 -15
- package/src/llm/providers/GeminiProvider.ts +51 -0
- package/src/llm/providers/OllamaProvider.ts +100 -15
- package/src/llm/providers/OpenAIProvider.ts +60 -11
- package/src/providers/vectordb/BaseVectorProvider.ts +11 -0
- package/src/providers/vectordb/MilvusProvider.ts +4 -0
- package/src/providers/vectordb/MongoDBProvider.ts +72 -8
- package/src/providers/vectordb/PineconeProvider.ts +60 -5
- package/src/providers/vectordb/PostgreSQLProvider.ts +84 -14
- package/src/providers/vectordb/QdrantProvider.ts +4 -0
- package/src/providers/vectordb/WeaviateProvider.ts +8 -4
- package/src/rag/DocumentChunker.ts +15 -19
- package/src/rag/LlamaIndexIngestor.ts +61 -0
- package/src/rag/Reranker.ts +20 -0
- package/src/server.ts +1 -1
- package/src/types/index.ts +9 -0
- package/dist/chunk-FWCSY2DS.mjs +0 -37
- package/dist/index-7qeLTPBL.d.mts +0 -114
- package/dist/index-DowY4_K0.d.ts +0 -114
|
@@ -32,7 +32,11 @@ export class DocumentChunker {
|
|
|
32
32
|
private readonly chunkOverlap: number;
|
|
33
33
|
private readonly separators: string[];
|
|
34
34
|
|
|
35
|
-
constructor(
|
|
35
|
+
constructor(
|
|
36
|
+
chunkSize = 1000,
|
|
37
|
+
chunkOverlap = 200,
|
|
38
|
+
separators = ['\n# ', '\n## ', '\n### ', '\n#### ', '\n\n', '\n', ' ', '']
|
|
39
|
+
) {
|
|
36
40
|
this.chunkSize = chunkSize;
|
|
37
41
|
this.chunkOverlap = chunkOverlap;
|
|
38
42
|
this.separators = separators;
|
|
@@ -40,6 +44,7 @@ export class DocumentChunker {
|
|
|
40
44
|
|
|
41
45
|
/**
|
|
42
46
|
* Split a single text string into overlapping chunks using a recursive strategy.
|
|
47
|
+
* Preserves structural boundaries (Markdown headers) where possible.
|
|
43
48
|
*/
|
|
44
49
|
chunk(text: string, options: ChunkOptions = {}): Chunk[] {
|
|
45
50
|
const {
|
|
@@ -58,19 +63,18 @@ export class DocumentChunker {
|
|
|
58
63
|
let chunkIndex = 0;
|
|
59
64
|
|
|
60
65
|
for (const split of splits) {
|
|
66
|
+
// If adding this split exceeds chunk size, and we already have content, close the chunk
|
|
61
67
|
if (currentLength + split.length > chunkSize && currentChunk.length > 0) {
|
|
62
|
-
// Current chunk is full, push it
|
|
63
68
|
finalChunks.push({
|
|
64
69
|
id: `${docId}_chunk_${chunkIndex++}`,
|
|
65
70
|
content: currentChunk.join('').trim(),
|
|
66
71
|
metadata: { ...metadata, docId, chunkIndex: chunkIndex - 1 },
|
|
67
72
|
});
|
|
68
73
|
|
|
69
|
-
//
|
|
70
|
-
// This is a simplified overlap: we keep items from the end of the previous chunk
|
|
71
|
-
// until we reach the overlap size.
|
|
74
|
+
// Sliding window overlap logic
|
|
72
75
|
const overlapItems = [];
|
|
73
76
|
let overlapLen = 0;
|
|
77
|
+
// Search backwards through current chunk to find segments that fit within the overlap window
|
|
74
78
|
for (let i = currentChunk.length - 1; i >= 0; i--) {
|
|
75
79
|
if (overlapLen + currentChunk[i].length <= chunkOverlap) {
|
|
76
80
|
overlapItems.unshift(currentChunk[i]);
|
|
@@ -99,35 +103,30 @@ export class DocumentChunker {
|
|
|
99
103
|
return finalChunks;
|
|
100
104
|
}
|
|
101
105
|
|
|
102
|
-
/**
|
|
103
|
-
* Recursively split text based on separators.
|
|
104
|
-
*/
|
|
105
106
|
private recursiveSplit(text: string, separators: string[], chunkSize: number): string[] {
|
|
106
107
|
const finalSplits: string[] = [];
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
let separator = separators[separators.length - 1]; // default to last (usually empty string)
|
|
109
|
+
let separator = separators[separators.length - 1];
|
|
110
110
|
let nextSeparators: string[] = [];
|
|
111
111
|
|
|
112
112
|
for (let i = 0; i < separators.length; i++) {
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
const sep = separators[i];
|
|
114
|
+
if (text.includes(sep)) {
|
|
115
|
+
separator = sep;
|
|
115
116
|
nextSeparators = separators.slice(i + 1);
|
|
116
117
|
break;
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
// Split the text
|
|
121
121
|
const parts = text.split(separator);
|
|
122
122
|
|
|
123
123
|
for (const part of parts) {
|
|
124
124
|
if (part.length <= chunkSize) {
|
|
125
|
-
|
|
125
|
+
// Keep the separator to preserve formatting/meaning
|
|
126
|
+
finalSplits.push(part + (part === parts[parts.length - 1] ? '' : separator));
|
|
126
127
|
} else if (nextSeparators.length > 0) {
|
|
127
|
-
// Part is too long, try splitting with next level separators
|
|
128
128
|
finalSplits.push(...this.recursiveSplit(part, nextSeparators, chunkSize));
|
|
129
129
|
} else {
|
|
130
|
-
// No more separators, just hard split (should not happen if empty string is the last separator)
|
|
131
130
|
finalSplits.push(part);
|
|
132
131
|
}
|
|
133
132
|
}
|
|
@@ -135,9 +134,6 @@ export class DocumentChunker {
|
|
|
135
134
|
return finalSplits;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
/**
|
|
139
|
-
* Chunk multiple documents at once.
|
|
140
|
-
*/
|
|
141
137
|
chunkMany(
|
|
142
138
|
documents: Array<{ content: string; docId?: string | number; metadata?: Record<string, unknown> }>
|
|
143
139
|
): Chunk[] {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Chunk, ChunkOptions } from './DocumentChunker';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LlamaIndexIngestor — Advanced ingestion provider using LlamaIndex (TS).
|
|
5
|
+
*
|
|
6
|
+
* Provides semantic chunking, metadata extraction, and node parsing
|
|
7
|
+
* superior to basic recursive character splitting.
|
|
8
|
+
*
|
|
9
|
+
* Note: Requires 'llamaindex' package to be installed.
|
|
10
|
+
*/
|
|
11
|
+
export class LlamaIndexIngestor {
|
|
12
|
+
/**
|
|
13
|
+
* Chunks document content using LlamaIndex SentenceSplitter.
|
|
14
|
+
* This respects sentence and paragraph boundaries much more effectively
|
|
15
|
+
* than standard character-count splitting.
|
|
16
|
+
*/
|
|
17
|
+
async chunk(text: string, options: ChunkOptions = {}): Promise<Chunk[]> {
|
|
18
|
+
try {
|
|
19
|
+
// Dynamically import for optional dependency support using template string to hide from TS static analysis
|
|
20
|
+
const { Document, SentenceSplitter, MetadataMode } = await import(`${'llamaindex'}`);
|
|
21
|
+
|
|
22
|
+
const splitter = new SentenceSplitter({
|
|
23
|
+
chunkSize: options.chunkSize ?? 1000,
|
|
24
|
+
chunkOverlap: options.chunkOverlap ?? 200,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const doc = new Document({ text, metadata: options.metadata || {} });
|
|
28
|
+
const nodes = splitter.getNodesFromDocuments([doc]);
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
return (nodes as any[]).map((node: any, index: number) => ({
|
|
32
|
+
id: `${options.docId || 'doc'}_node_${index}`,
|
|
33
|
+
content: node.getContent(MetadataMode.ALL),
|
|
34
|
+
metadata: {
|
|
35
|
+
...options.metadata,
|
|
36
|
+
...node.metadata,
|
|
37
|
+
nodeId: node.id_,
|
|
38
|
+
chunkIndex: index
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn('[LlamaIndexIngestor] LlamaIndex package not found or failed. Falling back to default chunker.');
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Batch processing for multiple documents.
|
|
49
|
+
*/
|
|
50
|
+
async chunkMany(
|
|
51
|
+
documents: Array<{ content: string; docId?: string | number; metadata?: Record<string, unknown> }>,
|
|
52
|
+
options: ChunkOptions = {}
|
|
53
|
+
): Promise<Chunk[]> {
|
|
54
|
+
const allChunks: Chunk[] = [];
|
|
55
|
+
for (const doc of documents) {
|
|
56
|
+
const chunks = await this.chunk(doc.content, { ...options, docId: doc.docId, metadata: doc.metadata });
|
|
57
|
+
allChunks.push(...chunks);
|
|
58
|
+
}
|
|
59
|
+
return allChunks;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VectorMatch } from '../types';
|
|
2
|
+
|
|
3
|
+
export class Reranker {
|
|
4
|
+
/**
|
|
5
|
+
* Re-ranks matches based on a secondary relevance score.
|
|
6
|
+
* In a production environment, this would call a Cross-Encoder model.
|
|
7
|
+
* Here we implement a placeholder that filters by score and limits count.
|
|
8
|
+
*/
|
|
9
|
+
async rerank(
|
|
10
|
+
matches: VectorMatch[],
|
|
11
|
+
query: string,
|
|
12
|
+
limit: number = 5
|
|
13
|
+
): Promise<VectorMatch[]> {
|
|
14
|
+
// Current implementation: sort by original score and apply a strict threshold
|
|
15
|
+
// and semantic match filtering (placeholder)
|
|
16
|
+
return matches
|
|
17
|
+
.sort((a, b) => b.score - a.score)
|
|
18
|
+
.slice(0, limit);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/server.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type { RagConfig, VectorDBConfig, LLMConfig, EmbeddingConfig, UIConfig, R
|
|
|
10
10
|
export type { VectorMatch, UpsertDocument, IngestDocument, ChatResponse } from './types';
|
|
11
11
|
export type { ILLMProvider, ChatMessage, ChatOptions, EmbedOptions } from './llm/ILLMProvider';
|
|
12
12
|
export type { Chunk, ChunkOptions } from './rag/DocumentChunker';
|
|
13
|
-
export type { HealthCheckResult } from './core/
|
|
13
|
+
export type { HealthCheckResult, IProviderValidator, IProviderHealthChecker } from './core/ProviderInterfaces';
|
|
14
14
|
export type { ValidationError } from './core/ConfigValidator';
|
|
15
15
|
export type { BatchOptions, BatchResult } from './core/BatchProcessor';
|
|
16
16
|
|
package/src/types/index.ts
CHANGED
|
@@ -41,3 +41,12 @@ export interface GraphSearchResult {
|
|
|
41
41
|
nodes: GraphNode[];
|
|
42
42
|
edges: Edge[];
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
export interface RetrievalResult {
|
|
46
|
+
sources: VectorMatch[];
|
|
47
|
+
graphData?: GraphSearchResult;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface IRetriever {
|
|
51
|
+
retrieve(query: string, options?: Record<string, unknown>): Promise<RetrievalResult>;
|
|
52
|
+
}
|
package/dist/chunk-FWCSY2DS.mjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
__spreadValues,
|
|
35
|
-
__spreadProps,
|
|
36
|
-
__objRest
|
|
37
|
-
};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { e as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, c as RagConfig, C as ChatResponse } from './RagConfig-BgRDL9Vy.mjs';
|
|
2
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ProviderHealthCheck.ts — Pre-flight validation for vector DB and LLM providers.
|
|
6
|
-
*
|
|
7
|
-
* Performs connectivity tests, credential validation, and capability checks
|
|
8
|
-
* before initializing providers.
|
|
9
|
-
*
|
|
10
|
-
* Note: Option keys used here mirror each Provider constructor's expected keys.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
interface HealthCheckResult {
|
|
14
|
-
healthy: boolean;
|
|
15
|
-
provider: string;
|
|
16
|
-
version?: string;
|
|
17
|
-
capabilities?: Record<string, unknown>;
|
|
18
|
-
error?: string;
|
|
19
|
-
timestamp: number;
|
|
20
|
-
}
|
|
21
|
-
declare class ProviderHealthCheck {
|
|
22
|
-
/**
|
|
23
|
-
* Validates vector database configuration before initialization.
|
|
24
|
-
*/
|
|
25
|
-
static checkVectorProvider(config: VectorDBConfig): Promise<HealthCheckResult>;
|
|
26
|
-
private static checkPinecone;
|
|
27
|
-
private static checkPostgres;
|
|
28
|
-
private static checkMongoDB;
|
|
29
|
-
/**
|
|
30
|
-
* Milvus health check — uses baseUrl/uri (matching MilvusProvider constructor).
|
|
31
|
-
*/
|
|
32
|
-
private static checkMilvus;
|
|
33
|
-
/**
|
|
34
|
-
* Qdrant health check — uses baseUrl (matching QdrantProvider constructor).
|
|
35
|
-
*/
|
|
36
|
-
private static checkQdrant;
|
|
37
|
-
/**
|
|
38
|
-
* ChromaDB health check — uses baseUrl/host (matching ChromaDBProvider constructor).
|
|
39
|
-
*/
|
|
40
|
-
private static checkChromaDB;
|
|
41
|
-
/**
|
|
42
|
-
* Redis health check — Redis is TCP-only (no HTTP endpoint).
|
|
43
|
-
* We report healthy=true with a note; actual connectivity is validated at first operation.
|
|
44
|
-
*/
|
|
45
|
-
private static checkRedis;
|
|
46
|
-
/**
|
|
47
|
-
* Weaviate health check — uses baseUrl/url (matching WeaviateProvider constructor).
|
|
48
|
-
*/
|
|
49
|
-
private static checkWeaviate;
|
|
50
|
-
private static checkRestAPI;
|
|
51
|
-
/**
|
|
52
|
-
* Validates LLM provider configuration.
|
|
53
|
-
*/
|
|
54
|
-
static checkLLMProvider(config: LLMConfig): Promise<HealthCheckResult>;
|
|
55
|
-
private static checkOpenAI;
|
|
56
|
-
private static checkAnthropic;
|
|
57
|
-
private static checkOllama;
|
|
58
|
-
private static checkLLMRestAPI;
|
|
59
|
-
/**
|
|
60
|
-
* Runs comprehensive health checks on all configured providers in parallel.
|
|
61
|
-
*/
|
|
62
|
-
static checkAll(vectorDbConfig: VectorDBConfig, llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): Promise<{
|
|
63
|
-
vectorDb: HealthCheckResult;
|
|
64
|
-
llm: HealthCheckResult;
|
|
65
|
-
embedding?: HealthCheckResult;
|
|
66
|
-
allHealthy: boolean;
|
|
67
|
-
}>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* createChatHandler — factory that returns a Next.js App Router POST handler
|
|
72
|
-
*/
|
|
73
|
-
declare function createChatHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
74
|
-
error: string;
|
|
75
|
-
}> | NextResponse<ChatResponse>>;
|
|
76
|
-
/**
|
|
77
|
-
* createIngestHandler — factory for the document ingestion endpoint.
|
|
78
|
-
*/
|
|
79
|
-
declare function createIngestHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
80
|
-
error: string;
|
|
81
|
-
}> | NextResponse<{
|
|
82
|
-
results: {
|
|
83
|
-
docId: string | number;
|
|
84
|
-
chunksIngested: number;
|
|
85
|
-
}[];
|
|
86
|
-
}>>;
|
|
87
|
-
/**
|
|
88
|
-
* createHealthHandler — factory for the health-check endpoint.
|
|
89
|
-
*/
|
|
90
|
-
declare function createHealthHandler(config?: Partial<RagConfig>): () => Promise<NextResponse<{
|
|
91
|
-
timestamp: string;
|
|
92
|
-
vectorDb: HealthCheckResult;
|
|
93
|
-
llm: HealthCheckResult;
|
|
94
|
-
embedding?: HealthCheckResult;
|
|
95
|
-
allHealthy: boolean;
|
|
96
|
-
status: string;
|
|
97
|
-
}> | NextResponse<{
|
|
98
|
-
status: string;
|
|
99
|
-
error: string;
|
|
100
|
-
}>>;
|
|
101
|
-
/**
|
|
102
|
-
* createUploadHandler — factory for the file upload ingestion endpoint.
|
|
103
|
-
*/
|
|
104
|
-
declare function createUploadHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
105
|
-
error: string;
|
|
106
|
-
}> | NextResponse<{
|
|
107
|
-
message: string;
|
|
108
|
-
results: {
|
|
109
|
-
docId: string | number;
|
|
110
|
-
chunksIngested: number;
|
|
111
|
-
}[];
|
|
112
|
-
}>>;
|
|
113
|
-
|
|
114
|
-
export { type HealthCheckResult as H, ProviderHealthCheck as P, createHealthHandler as a, createIngestHandler as b, createChatHandler as c, createUploadHandler as d };
|
package/dist/index-DowY4_K0.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { e as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, c as RagConfig, C as ChatResponse } from './RagConfig-BgRDL9Vy.js';
|
|
2
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ProviderHealthCheck.ts — Pre-flight validation for vector DB and LLM providers.
|
|
6
|
-
*
|
|
7
|
-
* Performs connectivity tests, credential validation, and capability checks
|
|
8
|
-
* before initializing providers.
|
|
9
|
-
*
|
|
10
|
-
* Note: Option keys used here mirror each Provider constructor's expected keys.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
interface HealthCheckResult {
|
|
14
|
-
healthy: boolean;
|
|
15
|
-
provider: string;
|
|
16
|
-
version?: string;
|
|
17
|
-
capabilities?: Record<string, unknown>;
|
|
18
|
-
error?: string;
|
|
19
|
-
timestamp: number;
|
|
20
|
-
}
|
|
21
|
-
declare class ProviderHealthCheck {
|
|
22
|
-
/**
|
|
23
|
-
* Validates vector database configuration before initialization.
|
|
24
|
-
*/
|
|
25
|
-
static checkVectorProvider(config: VectorDBConfig): Promise<HealthCheckResult>;
|
|
26
|
-
private static checkPinecone;
|
|
27
|
-
private static checkPostgres;
|
|
28
|
-
private static checkMongoDB;
|
|
29
|
-
/**
|
|
30
|
-
* Milvus health check — uses baseUrl/uri (matching MilvusProvider constructor).
|
|
31
|
-
*/
|
|
32
|
-
private static checkMilvus;
|
|
33
|
-
/**
|
|
34
|
-
* Qdrant health check — uses baseUrl (matching QdrantProvider constructor).
|
|
35
|
-
*/
|
|
36
|
-
private static checkQdrant;
|
|
37
|
-
/**
|
|
38
|
-
* ChromaDB health check — uses baseUrl/host (matching ChromaDBProvider constructor).
|
|
39
|
-
*/
|
|
40
|
-
private static checkChromaDB;
|
|
41
|
-
/**
|
|
42
|
-
* Redis health check — Redis is TCP-only (no HTTP endpoint).
|
|
43
|
-
* We report healthy=true with a note; actual connectivity is validated at first operation.
|
|
44
|
-
*/
|
|
45
|
-
private static checkRedis;
|
|
46
|
-
/**
|
|
47
|
-
* Weaviate health check — uses baseUrl/url (matching WeaviateProvider constructor).
|
|
48
|
-
*/
|
|
49
|
-
private static checkWeaviate;
|
|
50
|
-
private static checkRestAPI;
|
|
51
|
-
/**
|
|
52
|
-
* Validates LLM provider configuration.
|
|
53
|
-
*/
|
|
54
|
-
static checkLLMProvider(config: LLMConfig): Promise<HealthCheckResult>;
|
|
55
|
-
private static checkOpenAI;
|
|
56
|
-
private static checkAnthropic;
|
|
57
|
-
private static checkOllama;
|
|
58
|
-
private static checkLLMRestAPI;
|
|
59
|
-
/**
|
|
60
|
-
* Runs comprehensive health checks on all configured providers in parallel.
|
|
61
|
-
*/
|
|
62
|
-
static checkAll(vectorDbConfig: VectorDBConfig, llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): Promise<{
|
|
63
|
-
vectorDb: HealthCheckResult;
|
|
64
|
-
llm: HealthCheckResult;
|
|
65
|
-
embedding?: HealthCheckResult;
|
|
66
|
-
allHealthy: boolean;
|
|
67
|
-
}>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* createChatHandler — factory that returns a Next.js App Router POST handler
|
|
72
|
-
*/
|
|
73
|
-
declare function createChatHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
74
|
-
error: string;
|
|
75
|
-
}> | NextResponse<ChatResponse>>;
|
|
76
|
-
/**
|
|
77
|
-
* createIngestHandler — factory for the document ingestion endpoint.
|
|
78
|
-
*/
|
|
79
|
-
declare function createIngestHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
80
|
-
error: string;
|
|
81
|
-
}> | NextResponse<{
|
|
82
|
-
results: {
|
|
83
|
-
docId: string | number;
|
|
84
|
-
chunksIngested: number;
|
|
85
|
-
}[];
|
|
86
|
-
}>>;
|
|
87
|
-
/**
|
|
88
|
-
* createHealthHandler — factory for the health-check endpoint.
|
|
89
|
-
*/
|
|
90
|
-
declare function createHealthHandler(config?: Partial<RagConfig>): () => Promise<NextResponse<{
|
|
91
|
-
timestamp: string;
|
|
92
|
-
vectorDb: HealthCheckResult;
|
|
93
|
-
llm: HealthCheckResult;
|
|
94
|
-
embedding?: HealthCheckResult;
|
|
95
|
-
allHealthy: boolean;
|
|
96
|
-
status: string;
|
|
97
|
-
}> | NextResponse<{
|
|
98
|
-
status: string;
|
|
99
|
-
error: string;
|
|
100
|
-
}>>;
|
|
101
|
-
/**
|
|
102
|
-
* createUploadHandler — factory for the file upload ingestion endpoint.
|
|
103
|
-
*/
|
|
104
|
-
declare function createUploadHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
105
|
-
error: string;
|
|
106
|
-
}> | NextResponse<{
|
|
107
|
-
message: string;
|
|
108
|
-
results: {
|
|
109
|
-
docId: string | number;
|
|
110
|
-
chunksIngested: number;
|
|
111
|
-
}[];
|
|
112
|
-
}>>;
|
|
113
|
-
|
|
114
|
-
export { type HealthCheckResult as H, ProviderHealthCheck as P, createHealthHandler as a, createIngestHandler as b, createChatHandler as c, createUploadHandler as d };
|