@retrivora-ai/rag-engine 0.1.3 → 0.1.5
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/dist/ChromaDBProvider-QNI7UCX4.mjs +8 -0
- package/dist/DocumentChunker-cfaMidtA.d.mts +93 -0
- package/dist/DocumentChunker-cfaMidtA.d.ts +93 -0
- package/dist/LLMFactory-JFOY2V4X.mjs +8 -0
- package/dist/MilvusProvider-OO6QGZDZ.mjs +8 -0
- package/dist/MongoDBProvider-WWVJG3WT.mjs +8 -0
- package/dist/PineconeProvider-NJ675H7U.mjs +8 -0
- package/dist/PostgreSQLProvider-ISNMD3BE.mjs +8 -0
- package/dist/QdrantProvider-LJWOIGES.mjs +8 -0
- package/dist/RagConfig-DG_0f8ka.d.mts +145 -0
- package/dist/RagConfig-DG_0f8ka.d.ts +145 -0
- package/dist/RedisProvider-ASONNYBI.mjs +8 -0
- package/dist/WeaviateProvider-PSDCUGC7.mjs +8 -0
- package/dist/chunk-6FODXNUF.mjs +91 -0
- package/dist/chunk-7NXI6ZWX.mjs +89 -0
- package/dist/chunk-AALIF3AL.mjs +91 -0
- package/dist/chunk-BP4U4TT5.mjs +548 -0
- package/dist/chunk-HUGLYKD6.mjs +84 -0
- package/dist/chunk-I4E63NIC.mjs +24 -0
- package/dist/chunk-JI6VD5TJ.mjs +387 -0
- package/dist/chunk-QEYVWVT5.mjs +102 -0
- package/dist/chunk-S5DRHETN.mjs +110 -0
- package/dist/{chunk-ZPXLQR5Q.mjs → chunk-UKDXCXW7.mjs} +5 -23
- package/dist/chunk-V75V7BT2.mjs +117 -0
- package/dist/chunk-VOIWNO5O.mjs +11 -0
- package/dist/chunk-VPNRDXIA.mjs +74 -0
- package/dist/handlers/index.d.mts +9 -33
- package/dist/handlers/index.d.ts +9 -33
- package/dist/handlers/index.js +1477 -962
- package/dist/handlers/index.mjs +4 -2
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/index.mjs +4 -2
- package/dist/server.d.mts +220 -53
- package/dist/server.d.ts +220 -53
- package/dist/server.js +1531 -1099
- package/dist/server.mjs +55 -131
- package/package.json +19 -2
- package/src/app/page.tsx +1 -1
- package/src/components/MessageBubble.tsx +1 -1
- package/src/components/SourceCard.tsx +1 -1
- package/src/config/RagConfig.ts +1 -1
- package/src/config/serverConfig.ts +2 -2
- package/src/core/ConfigResolver.ts +69 -0
- package/src/core/Pipeline.ts +101 -0
- package/src/core/ProviderRegistry.ts +71 -0
- package/src/core/VectorPlugin.ts +52 -0
- package/src/handlers/index.ts +21 -100
- package/src/hooks/useRagChat.ts +1 -1
- package/src/index.ts +2 -6
- package/src/providers/vectordb/BaseVectorProvider.ts +61 -0
- package/src/providers/vectordb/ChromaDBProvider.ts +94 -0
- package/src/providers/vectordb/MilvusProvider.ts +100 -0
- package/src/providers/vectordb/MongoDBProvider.ts +118 -0
- package/src/{vectordb/adapters/PineconeAdapter.ts → providers/vectordb/PineconeProvider.ts} +21 -56
- package/src/{vectordb/adapters/PgVectorAdapter.ts → providers/vectordb/PostgreSQLProvider.ts} +23 -58
- package/src/providers/vectordb/QdrantProvider.ts +95 -0
- package/src/providers/vectordb/RedisProvider.ts +84 -0
- package/src/providers/vectordb/WeaviateProvider.ts +124 -0
- package/src/server.ts +16 -8
- package/src/test-refactor.ts +59 -0
- package/src/types/index.ts +24 -0
- package/src/utils/templateUtils.ts +6 -6
- package/dist/DocumentChunker-BUrIrcPk.d.mts +0 -43
- package/dist/DocumentChunker-BUrIrcPk.d.ts +0 -43
- package/dist/RAGPipeline-BmkIv1HD.d.mts +0 -298
- package/dist/RAGPipeline-BmkIv1HD.d.ts +0 -298
- package/dist/chunk-NVOMLHXW.mjs +0 -1259
- package/src/rag/RAGPipeline.ts +0 -200
- package/src/vectordb/IVectorDB.ts +0 -75
- package/src/vectordb/VectorDBFactory.ts +0 -41
- package/src/vectordb/adapters/MongoDbAdapter.ts +0 -175
- package/src/vectordb/adapters/UniversalVectorDBAdapter.ts +0 -177
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseVectorProvider
|
|
3
|
+
} from "./chunk-VOIWNO5O.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "./chunk-I4E63NIC.mjs";
|
|
7
|
+
|
|
8
|
+
// src/providers/vectordb/WeaviateProvider.ts
|
|
9
|
+
import axios from "axios";
|
|
10
|
+
var WeaviateProvider = class extends BaseVectorProvider {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super(config);
|
|
13
|
+
const opts = config.options;
|
|
14
|
+
const baseUrl = opts.baseUrl;
|
|
15
|
+
if (!baseUrl) throw new Error("[WeaviateProvider] baseUrl is required");
|
|
16
|
+
this.http = axios.create({
|
|
17
|
+
baseURL: baseUrl,
|
|
18
|
+
headers: __spreadValues({
|
|
19
|
+
"Content-Type": "application/json"
|
|
20
|
+
}, opts.apiKey ? {
|
|
21
|
+
"X-OpenAI-Api-Key": opts.apiKey,
|
|
22
|
+
"Authorization": `Bearer ${opts.apiKey}`
|
|
23
|
+
} : {})
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async initialize() {
|
|
27
|
+
await this.ping();
|
|
28
|
+
}
|
|
29
|
+
async upsert(doc, namespace) {
|
|
30
|
+
const payload = {
|
|
31
|
+
class: this.indexName,
|
|
32
|
+
id: doc.id,
|
|
33
|
+
vector: doc.vector,
|
|
34
|
+
properties: {
|
|
35
|
+
content: doc.content,
|
|
36
|
+
metadata: JSON.stringify(doc.metadata || {}),
|
|
37
|
+
namespace: namespace || ""
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
await this.http.post("/v1/objects", payload);
|
|
41
|
+
}
|
|
42
|
+
async batchUpsert(docs, namespace) {
|
|
43
|
+
const payload = {
|
|
44
|
+
objects: docs.map((doc) => ({
|
|
45
|
+
class: this.indexName,
|
|
46
|
+
id: doc.id,
|
|
47
|
+
vector: doc.vector,
|
|
48
|
+
properties: {
|
|
49
|
+
content: doc.content,
|
|
50
|
+
metadata: JSON.stringify(doc.metadata || {}),
|
|
51
|
+
namespace: namespace || ""
|
|
52
|
+
}
|
|
53
|
+
}))
|
|
54
|
+
};
|
|
55
|
+
await this.http.post("/v1/batch/objects", payload);
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
|
+
async query(vector, topK, namespace, _filter) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const graphqlQuery = {
|
|
61
|
+
query: `
|
|
62
|
+
{
|
|
63
|
+
Get {
|
|
64
|
+
${this.indexName}(
|
|
65
|
+
nearVector: {
|
|
66
|
+
vector: ${JSON.stringify(vector)}
|
|
67
|
+
}
|
|
68
|
+
limit: ${topK}
|
|
69
|
+
${namespace ? `where: { path: ["namespace"], operator: Equal, valueString: "${namespace}" }` : ""}
|
|
70
|
+
) {
|
|
71
|
+
content
|
|
72
|
+
metadata
|
|
73
|
+
_additional {
|
|
74
|
+
id
|
|
75
|
+
distance
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
`
|
|
81
|
+
};
|
|
82
|
+
const { data } = await this.http.post("/v1/graphql", graphqlQuery);
|
|
83
|
+
const results = ((_b = (_a = data.data) == null ? void 0 : _a.Get) == null ? void 0 : _b[this.indexName]) || [];
|
|
84
|
+
return results.map((res) => ({
|
|
85
|
+
id: res["_additional"].id,
|
|
86
|
+
score: 1 - res["_additional"].distance,
|
|
87
|
+
content: res["content"],
|
|
88
|
+
metadata: res["metadata"] ? JSON.parse(res["metadata"]) : {}
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
92
|
+
async delete(id, _namespace) {
|
|
93
|
+
await this.http.delete(`/v1/objects/${this.indexName}/${id}`);
|
|
94
|
+
}
|
|
95
|
+
async deleteNamespace(namespace) {
|
|
96
|
+
await this.http.post("/v1/batch/objects", {
|
|
97
|
+
match: {
|
|
98
|
+
class: this.indexName,
|
|
99
|
+
where: { path: ["namespace"], operator: "Equal", valueString: namespace }
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
async ping() {
|
|
104
|
+
try {
|
|
105
|
+
await this.http.get("/v1/.well-known/live");
|
|
106
|
+
return true;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async disconnect() {
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
WeaviateProvider
|
|
117
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseVectorProvider
|
|
3
|
+
} from "./chunk-VOIWNO5O.mjs";
|
|
4
|
+
|
|
5
|
+
// src/providers/vectordb/RedisProvider.ts
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
var RedisProvider = class extends BaseVectorProvider {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
super(config);
|
|
10
|
+
const opts = config.options;
|
|
11
|
+
const baseUrl = opts.baseUrl;
|
|
12
|
+
if (!baseUrl) throw new Error("[RedisProvider] baseUrl is required");
|
|
13
|
+
this.http = axios.create({
|
|
14
|
+
baseURL: baseUrl,
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
Authorization: `Bearer ${opts.apiKey}`
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async initialize() {
|
|
22
|
+
await this.ping();
|
|
23
|
+
}
|
|
24
|
+
async upsert(doc, namespace) {
|
|
25
|
+
const key = namespace ? `${namespace}:${doc.id}` : doc.id;
|
|
26
|
+
await this.http.post("/", ["JSON.SET", key, "$", JSON.stringify({
|
|
27
|
+
vector: doc.vector,
|
|
28
|
+
content: doc.content,
|
|
29
|
+
metadata: doc.metadata || {}
|
|
30
|
+
})]);
|
|
31
|
+
}
|
|
32
|
+
async batchUpsert(docs, namespace) {
|
|
33
|
+
for (const doc of docs) {
|
|
34
|
+
await this.upsert(doc, namespace);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
38
|
+
async query(vector, topK, namespace, _filter) {
|
|
39
|
+
const payload = {
|
|
40
|
+
index: this.indexName,
|
|
41
|
+
vector,
|
|
42
|
+
topK,
|
|
43
|
+
namespace
|
|
44
|
+
};
|
|
45
|
+
const { data } = await this.http.post("/search", payload);
|
|
46
|
+
return (data.results || []).map((res) => ({
|
|
47
|
+
id: res["id"],
|
|
48
|
+
score: res["score"],
|
|
49
|
+
content: res["content"],
|
|
50
|
+
metadata: res["metadata"]
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
async delete(id, namespace) {
|
|
54
|
+
const key = namespace ? `${namespace}:${id}` : id;
|
|
55
|
+
await this.http.post("/", ["DEL", key]);
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
|
+
async deleteNamespace(_namespace) {
|
|
59
|
+
}
|
|
60
|
+
async ping() {
|
|
61
|
+
try {
|
|
62
|
+
await this.http.post("/", ["PING"]);
|
|
63
|
+
return true;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async disconnect() {
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
RedisProvider
|
|
74
|
+
};
|
|
@@ -1,68 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as RagConfig, C as ChatResponse } from '../RagConfig-DG_0f8ka.mjs';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
declare function createChatHandler(config: RagConfig, adapters?: CustomAdapters): (req: NextRequest) => Promise<NextResponse<{
|
|
4
|
+
/**
|
|
5
|
+
* createChatHandler — factory that returns a Next.js App Router POST handler
|
|
6
|
+
*/
|
|
7
|
+
declare function createChatHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
10
8
|
error: string;
|
|
11
9
|
}> | NextResponse<ChatResponse>>;
|
|
12
10
|
/**
|
|
13
11
|
* createIngestHandler — factory for the document ingestion endpoint.
|
|
14
|
-
*
|
|
15
|
-
* Usage — in your project's `src/app/api/ingest/route.ts`:
|
|
16
|
-
*
|
|
17
|
-
* import { createIngestHandler } from '@rag/ai-accelerator/handlers';
|
|
18
|
-
* export const POST = createIngestHandler(myConfig, { vectorDB: new MyCustomDB() });
|
|
19
12
|
*/
|
|
20
|
-
declare function createIngestHandler(config
|
|
13
|
+
declare function createIngestHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
21
14
|
error: string;
|
|
22
15
|
}> | NextResponse<{
|
|
23
16
|
results: {
|
|
24
17
|
docId: string;
|
|
25
18
|
chunksIngested: number;
|
|
26
19
|
}[];
|
|
27
|
-
totalChunks: number;
|
|
28
20
|
}>>;
|
|
29
21
|
/**
|
|
30
22
|
* createHealthHandler — factory for the health-check endpoint.
|
|
31
|
-
*
|
|
32
|
-
* Usage — in your project's `src/app/api/health/route.ts`:
|
|
33
|
-
*
|
|
34
|
-
* import { createHealthHandler } from '@rag/ai-accelerator/handlers';
|
|
35
|
-
* export const GET = createHealthHandler(myConfig, { vectorDB: new MyCustomDB() });
|
|
36
23
|
*/
|
|
37
|
-
declare function createHealthHandler(config
|
|
38
|
-
project: string;
|
|
24
|
+
declare function createHealthHandler(config?: Partial<RagConfig>): () => Promise<NextResponse<{
|
|
39
25
|
timestamp: string;
|
|
40
|
-
vectorDB: boolean;
|
|
41
|
-
llm: boolean;
|
|
42
26
|
status: string;
|
|
43
27
|
}> | NextResponse<{
|
|
44
28
|
status: string;
|
|
45
29
|
error: string;
|
|
46
|
-
timestamp: string;
|
|
47
30
|
}>>;
|
|
48
31
|
/**
|
|
49
32
|
* createUploadHandler — factory for the file upload ingestion endpoint.
|
|
50
|
-
*
|
|
51
|
-
* Usage — in your project's `src/app/api/upload/route.ts`:
|
|
52
|
-
*
|
|
53
|
-
* import { createUploadHandler } from '@rag/ai-accelerator/handlers';
|
|
54
|
-
* export const POST = createUploadHandler(myConfig);
|
|
55
33
|
*/
|
|
56
|
-
declare function createUploadHandler(config
|
|
34
|
+
declare function createUploadHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
57
35
|
error: string;
|
|
58
36
|
}> | NextResponse<{
|
|
59
37
|
message: string;
|
|
60
|
-
filesProcessed: number;
|
|
61
|
-
totalChunks: number;
|
|
62
38
|
results: {
|
|
63
39
|
docId: string;
|
|
64
40
|
chunksIngested: number;
|
|
65
41
|
}[];
|
|
66
42
|
}>>;
|
|
67
43
|
|
|
68
|
-
export {
|
|
44
|
+
export { createChatHandler, createHealthHandler, createIngestHandler, createUploadHandler };
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -1,68 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as RagConfig, C as ChatResponse } from '../RagConfig-DG_0f8ka.js';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
declare function createChatHandler(config: RagConfig, adapters?: CustomAdapters): (req: NextRequest) => Promise<NextResponse<{
|
|
4
|
+
/**
|
|
5
|
+
* createChatHandler — factory that returns a Next.js App Router POST handler
|
|
6
|
+
*/
|
|
7
|
+
declare function createChatHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
10
8
|
error: string;
|
|
11
9
|
}> | NextResponse<ChatResponse>>;
|
|
12
10
|
/**
|
|
13
11
|
* createIngestHandler — factory for the document ingestion endpoint.
|
|
14
|
-
*
|
|
15
|
-
* Usage — in your project's `src/app/api/ingest/route.ts`:
|
|
16
|
-
*
|
|
17
|
-
* import { createIngestHandler } from '@rag/ai-accelerator/handlers';
|
|
18
|
-
* export const POST = createIngestHandler(myConfig, { vectorDB: new MyCustomDB() });
|
|
19
12
|
*/
|
|
20
|
-
declare function createIngestHandler(config
|
|
13
|
+
declare function createIngestHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
21
14
|
error: string;
|
|
22
15
|
}> | NextResponse<{
|
|
23
16
|
results: {
|
|
24
17
|
docId: string;
|
|
25
18
|
chunksIngested: number;
|
|
26
19
|
}[];
|
|
27
|
-
totalChunks: number;
|
|
28
20
|
}>>;
|
|
29
21
|
/**
|
|
30
22
|
* createHealthHandler — factory for the health-check endpoint.
|
|
31
|
-
*
|
|
32
|
-
* Usage — in your project's `src/app/api/health/route.ts`:
|
|
33
|
-
*
|
|
34
|
-
* import { createHealthHandler } from '@rag/ai-accelerator/handlers';
|
|
35
|
-
* export const GET = createHealthHandler(myConfig, { vectorDB: new MyCustomDB() });
|
|
36
23
|
*/
|
|
37
|
-
declare function createHealthHandler(config
|
|
38
|
-
project: string;
|
|
24
|
+
declare function createHealthHandler(config?: Partial<RagConfig>): () => Promise<NextResponse<{
|
|
39
25
|
timestamp: string;
|
|
40
|
-
vectorDB: boolean;
|
|
41
|
-
llm: boolean;
|
|
42
26
|
status: string;
|
|
43
27
|
}> | NextResponse<{
|
|
44
28
|
status: string;
|
|
45
29
|
error: string;
|
|
46
|
-
timestamp: string;
|
|
47
30
|
}>>;
|
|
48
31
|
/**
|
|
49
32
|
* createUploadHandler — factory for the file upload ingestion endpoint.
|
|
50
|
-
*
|
|
51
|
-
* Usage — in your project's `src/app/api/upload/route.ts`:
|
|
52
|
-
*
|
|
53
|
-
* import { createUploadHandler } from '@rag/ai-accelerator/handlers';
|
|
54
|
-
* export const POST = createUploadHandler(myConfig);
|
|
55
33
|
*/
|
|
56
|
-
declare function createUploadHandler(config
|
|
34
|
+
declare function createUploadHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
57
35
|
error: string;
|
|
58
36
|
}> | NextResponse<{
|
|
59
37
|
message: string;
|
|
60
|
-
filesProcessed: number;
|
|
61
|
-
totalChunks: number;
|
|
62
38
|
results: {
|
|
63
39
|
docId: string;
|
|
64
40
|
chunksIngested: number;
|
|
65
41
|
}[];
|
|
66
42
|
}>>;
|
|
67
43
|
|
|
68
|
-
export {
|
|
44
|
+
export { createChatHandler, createHealthHandler, createIngestHandler, createUploadHandler };
|