@retrivora-ai/rag-engine 0.1.4 → 0.1.6
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/DocumentChunker-BEyzadsv.d.mts +93 -0
- package/dist/DocumentChunker-BEyzadsv.d.ts +93 -0
- package/dist/{LLMFactory-XC55FTD2.mjs → LLMFactory-JFOY2V4X.mjs} +2 -1
- package/dist/{PineconeProvider-NJ675H7U.mjs → PineconeProvider-ZRAFNFEC.mjs} +1 -1
- package/dist/{PostgreSQLProvider-ISNMD3BE.mjs → PostgreSQLProvider-ZNXA67IM.mjs} +1 -1
- package/dist/{QdrantProvider-LJWOIGES.mjs → QdrantProvider-NYGHAA7C.mjs} +1 -1
- package/dist/{Pipeline-Bo6CUCox.d.mts → RagConfig-hBGXJmSx.d.mts} +23 -93
- package/dist/{Pipeline-Bo6CUCox.d.ts → RagConfig-hBGXJmSx.d.ts} +23 -93
- package/dist/{chunk-6FODXNUF.mjs → chunk-5K23H7JL.mjs} +27 -1
- package/dist/chunk-HSBXE2WV.mjs +1758 -0
- package/dist/{chunk-S5DRHETN.mjs → chunk-IUTAZ7QR.mjs} +31 -2
- package/dist/{chunk-GD3QJFNN.mjs → chunk-JI6VD5TJ.mjs} +4 -41
- package/dist/chunk-UKDXCXW7.mjs +49 -0
- package/dist/{chunk-AALIF3AL.mjs → chunk-ZM6TYIDH.mjs} +3 -3
- package/dist/handlers/index.d.mts +3 -44
- package/dist/handlers/index.d.ts +3 -44
- package/dist/handlers/index.js +1322 -57
- package/dist/handlers/index.mjs +3 -3
- package/dist/index-Bx182KKn.d.ts +64 -0
- package/dist/index-Ck2pt7-8.d.mts +64 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +19 -1646
- package/dist/index.mjs +1 -11
- package/dist/server.d.mts +188 -11
- package/dist/server.d.ts +188 -11
- package/dist/server.js +1322 -57
- package/dist/server.mjs +10 -11
- package/package.json +20 -2
- package/src/config/serverConfig.ts +3 -0
- package/src/core/BatchProcessor.ts +347 -0
- package/src/core/ConfigValidator.ts +560 -0
- package/src/core/Pipeline.ts +91 -49
- package/src/core/ProviderHealthCheck.ts +565 -0
- package/src/core/VectorPlugin.ts +51 -9
- package/src/handlers/index.ts +2 -2
- package/src/index.ts +1 -7
- package/src/providers/vectordb/BaseVectorProvider.ts +1 -1
- package/src/providers/vectordb/MilvusProvider.ts +1 -1
- package/src/providers/vectordb/MongoDBProvider.ts +1 -1
- package/src/providers/vectordb/PineconeProvider.ts +4 -4
- package/src/providers/vectordb/PostgreSQLProvider.ts +35 -3
- package/src/providers/vectordb/QdrantProvider.ts +32 -2
- package/src/rag/DocumentChunker.ts +2 -2
- package/src/server.ts +1 -1
- package/src/types/index.ts +13 -2
- package/dist/DocumentChunker-BQ5kQD7B.d.ts +0 -155
- package/dist/DocumentChunker-D9-fObJp.d.mts +0 -155
- package/dist/chunk-AIAB2IEE.mjs +0 -394
- package/dist/chunk-FGGSVVSY.mjs +0 -162
|
@@ -74,7 +74,7 @@ export class MilvusProvider extends BaseVectorProvider {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
77
|
-
async delete(id: string, _namespace?: string): Promise<void> {
|
|
77
|
+
async delete(id: string | number, _namespace?: string): Promise<void> {
|
|
78
78
|
await this.http.post('/v1/vector/delete', {
|
|
79
79
|
collectionName: this.indexName,
|
|
80
80
|
id: id,
|
|
@@ -95,7 +95,7 @@ export class MongoDBProvider extends BaseVectorProvider {
|
|
|
95
95
|
}));
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
async delete(id: string, namespace?: string): Promise<void> {
|
|
98
|
+
async delete(id: string | number, namespace?: string): Promise<void> {
|
|
99
99
|
await this.collection!.deleteOne({ _id: id, ...(namespace ? { namespace } : {}) });
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -31,7 +31,7 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
31
31
|
async upsert(doc: UpsertDocument, namespace?: string): Promise<void> {
|
|
32
32
|
await this.index(namespace).upsert({
|
|
33
33
|
records: [{
|
|
34
|
-
id: doc.id,
|
|
34
|
+
id: String(doc.id),
|
|
35
35
|
values: doc.vector,
|
|
36
36
|
metadata: { content: doc.content, ...(doc.metadata ?? {}) } as RecordMetadata,
|
|
37
37
|
}],
|
|
@@ -42,7 +42,7 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
42
42
|
const BATCH = 100;
|
|
43
43
|
for (let i = 0; i < docs.length; i += BATCH) {
|
|
44
44
|
const records = docs.slice(i, i + BATCH).map((d) => ({
|
|
45
|
-
id: d.id,
|
|
45
|
+
id: String(d.id),
|
|
46
46
|
values: d.vector,
|
|
47
47
|
metadata: { content: d.content, ...(d.metadata ?? {}) } as RecordMetadata,
|
|
48
48
|
}));
|
|
@@ -65,8 +65,8 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
65
65
|
}));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
async delete(id: string, namespace?: string): Promise<void> {
|
|
69
|
-
await this.index(namespace).deleteOne({ id });
|
|
68
|
+
async delete(id: string | number, namespace?: string): Promise<void> {
|
|
69
|
+
await this.index(namespace).deleteOne({ id: String(id) });
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
async deleteNamespace(namespace: string): Promise<void> {
|
|
@@ -60,8 +60,40 @@ export class PostgreSQLProvider extends BaseVectorProvider {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
async batchUpsert(docs: UpsertDocument[], namespace = ''): Promise<void> {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
if (docs.length === 0) return;
|
|
64
|
+
|
|
65
|
+
const client = await this.pool.connect();
|
|
66
|
+
try {
|
|
67
|
+
await client.query('BEGIN');
|
|
68
|
+
|
|
69
|
+
const BATCH_SIZE = 50;
|
|
70
|
+
for (let i = 0; i < docs.length; i += BATCH_SIZE) {
|
|
71
|
+
const batch = docs.slice(i, i + BATCH_SIZE);
|
|
72
|
+
const values: unknown[] = [];
|
|
73
|
+
const valuePlaceholders = batch.map((doc, idx) => {
|
|
74
|
+
const offset = idx * 5;
|
|
75
|
+
values.push(doc.id, namespace, doc.content, JSON.stringify(doc.metadata ?? {}), `[${doc.vector.join(',')}]`);
|
|
76
|
+
return `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}::vector)`;
|
|
77
|
+
}).join(', ');
|
|
78
|
+
|
|
79
|
+
const query = `
|
|
80
|
+
INSERT INTO ${this.tableName} (id, namespace, content, metadata, embedding)
|
|
81
|
+
VALUES ${valuePlaceholders}
|
|
82
|
+
ON CONFLICT (id) DO UPDATE
|
|
83
|
+
SET namespace = EXCLUDED.namespace,
|
|
84
|
+
content = EXCLUDED.content,
|
|
85
|
+
metadata = EXCLUDED.metadata,
|
|
86
|
+
embedding = EXCLUDED.embedding
|
|
87
|
+
`;
|
|
88
|
+
await client.query(query, values);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
await client.query('COMMIT');
|
|
92
|
+
} catch (error) {
|
|
93
|
+
await client.query('ROLLBACK');
|
|
94
|
+
throw error;
|
|
95
|
+
} finally {
|
|
96
|
+
client.release();
|
|
65
97
|
}
|
|
66
98
|
}
|
|
67
99
|
|
|
@@ -99,7 +131,7 @@ export class PostgreSQLProvider extends BaseVectorProvider {
|
|
|
99
131
|
}));
|
|
100
132
|
}
|
|
101
133
|
|
|
102
|
-
async delete(id: string, namespace?: string): Promise<void> {
|
|
134
|
+
async delete(id: string | number, namespace?: string): Promise<void> {
|
|
103
135
|
const where = namespace ? 'WHERE id = $1 AND namespace = $2' : 'WHERE id = $1';
|
|
104
136
|
const params = namespace ? [id, namespace] : [id];
|
|
105
137
|
await this.pool.query(`DELETE FROM ${this.tableName} ${where}`, params);
|
|
@@ -26,6 +26,37 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
26
26
|
|
|
27
27
|
async initialize(): Promise<void> {
|
|
28
28
|
await this.ping();
|
|
29
|
+
await this.ensureIndex();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Ensures that the 'namespace' field has a keyword index for efficient filtering.
|
|
34
|
+
* Qdrant requires this for search filters to work in many configurations.
|
|
35
|
+
*/
|
|
36
|
+
private async ensureIndex(): Promise<void> {
|
|
37
|
+
try {
|
|
38
|
+
await this.http.put(`/collections/${this.indexName}/index`, {
|
|
39
|
+
field_name: 'namespace',
|
|
40
|
+
field_schema: 'keyword',
|
|
41
|
+
});
|
|
42
|
+
console.log(`[QdrantProvider] ✅ Ensured keyword index for "namespace" on collection "${this.indexName}"`);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
let status: number | undefined;
|
|
45
|
+
let data: unknown;
|
|
46
|
+
|
|
47
|
+
if (axios.isAxiosError(err)) {
|
|
48
|
+
status = err.response?.status;
|
|
49
|
+
data = err.response?.data;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 409 means it already exists, which is fine.
|
|
53
|
+
if (status === 409) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
58
|
+
console.warn(`[QdrantProvider] ⚠️ Could not ensure namespace index (Status: ${status}):`, JSON.stringify(data || errorMessage));
|
|
59
|
+
}
|
|
29
60
|
}
|
|
30
61
|
|
|
31
62
|
async upsert(doc: UpsertDocument, namespace?: string): Promise<void> {
|
|
@@ -67,13 +98,12 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
67
98
|
}
|
|
68
99
|
|
|
69
100
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
-
async delete(id: string, _namespace?: string): Promise<void> {
|
|
101
|
+
async delete(id: string | number, _namespace?: string): Promise<void> {
|
|
71
102
|
await this.http.post(`/collections/${this.indexName}/points/delete`, {
|
|
72
103
|
points: [id],
|
|
73
104
|
});
|
|
74
105
|
}
|
|
75
106
|
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
77
107
|
async deleteNamespace(_namespace: string): Promise<void> {
|
|
78
108
|
await this.http.post(`/collections/${this.indexName}/points/delete`, {
|
|
79
109
|
filter: {
|
|
@@ -20,7 +20,7 @@ export interface ChunkOptions {
|
|
|
20
20
|
/** Overlap between consecutive chunks in characters (default 200) */
|
|
21
21
|
chunkOverlap?: number;
|
|
22
22
|
/** Source document identifier used as ID prefix */
|
|
23
|
-
docId?: string;
|
|
23
|
+
docId?: string | number;
|
|
24
24
|
/** Extra metadata to attach to every chunk */
|
|
25
25
|
metadata?: Record<string, unknown>;
|
|
26
26
|
}
|
|
@@ -96,7 +96,7 @@ export class DocumentChunker {
|
|
|
96
96
|
* Chunk multiple documents at once.
|
|
97
97
|
*/
|
|
98
98
|
chunkMany(
|
|
99
|
-
documents: Array<{ content: string; docId?: string; metadata?: Record<string, unknown> }>
|
|
99
|
+
documents: Array<{ content: string; docId?: string | number; metadata?: Record<string, unknown> }>
|
|
100
100
|
): Chunk[] {
|
|
101
101
|
return documents.flatMap((doc) =>
|
|
102
102
|
this.chunk(doc.content, { docId: doc.docId, metadata: doc.metadata })
|
package/src/server.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
export type { RagConfig, VectorDBConfig, LLMConfig, EmbeddingConfig, UIConfig, RAGConfig } from './config/RagConfig';
|
|
8
8
|
export type { VectorMatch, UpsertDocument } from './types';
|
|
9
9
|
export type { ILLMProvider, ChatMessage, ChatOptions, EmbedOptions } from './llm/ILLMProvider';
|
|
10
|
-
export type { IngestDocument, ChatResponse } from './
|
|
10
|
+
export type { IngestDocument, ChatResponse } from './types';
|
|
11
11
|
export type { Chunk, ChunkOptions } from './rag/DocumentChunker';
|
|
12
12
|
|
|
13
13
|
// ── Server-Only Logic (Node.js dependent) ─────────────────────
|
package/src/types/index.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
export interface VectorMatch {
|
|
2
|
-
id: string;
|
|
2
|
+
id: string | number;
|
|
3
3
|
score: number;
|
|
4
4
|
content: string;
|
|
5
5
|
metadata?: Record<string, unknown>;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface UpsertDocument {
|
|
9
|
-
id: string;
|
|
9
|
+
id: string | number;
|
|
10
10
|
vector: number[];
|
|
11
11
|
content: string;
|
|
12
12
|
metadata?: Record<string, unknown>;
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
export interface IngestDocument {
|
|
16
|
+
docId: string | number;
|
|
17
|
+
content: string;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ChatResponse {
|
|
22
|
+
reply: string;
|
|
23
|
+
sources: VectorMatch[];
|
|
24
|
+
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { e as RagConfig, C as ChatMessage, b as ChatResponse, d as IngestDocument, g as VectorDBConfig, f as UpsertDocument, V as VectorMatch, L as LLMConfig, c as EmbeddingConfig, I as ILLMProvider } from './Pipeline-Bo6CUCox.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* VectorPlugin — main orchestrator class.
|
|
5
|
-
* This is the primary interface for host applications.
|
|
6
|
-
*/
|
|
7
|
-
declare class VectorPlugin {
|
|
8
|
-
private config;
|
|
9
|
-
private pipeline;
|
|
10
|
-
/**
|
|
11
|
-
* Initializes the plugin with the host configuration.
|
|
12
|
-
* @param hostConfig - Configuration object passed from the host application.
|
|
13
|
-
*/
|
|
14
|
-
constructor(hostConfig?: Partial<RagConfig>);
|
|
15
|
-
/**
|
|
16
|
-
* Get the current resolved configuration.
|
|
17
|
-
*/
|
|
18
|
-
getConfig(): RagConfig;
|
|
19
|
-
/**
|
|
20
|
-
* Run a chat query.
|
|
21
|
-
*/
|
|
22
|
-
chat(message: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
|
|
23
|
-
/**
|
|
24
|
-
* Ingest documents into the vector database.
|
|
25
|
-
*/
|
|
26
|
-
ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
|
|
27
|
-
docId: string;
|
|
28
|
-
chunksIngested: number;
|
|
29
|
-
}>>;
|
|
30
|
-
/**
|
|
31
|
-
* Check the health of the connected providers.
|
|
32
|
-
*/
|
|
33
|
-
health(): Promise<Record<string, boolean>>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* ConfigResolver — validates and normalizes host configuration.
|
|
38
|
-
* It merges host-provided config with environment defaults.
|
|
39
|
-
*/
|
|
40
|
-
declare class ConfigResolver {
|
|
41
|
-
/**
|
|
42
|
-
* Resolves the final configuration by merging host-provided config with defaults.
|
|
43
|
-
* @param hostConfig - Partial configuration passed from the host application.
|
|
44
|
-
*/
|
|
45
|
-
static resolve(hostConfig?: Partial<RagConfig>): RagConfig;
|
|
46
|
-
/**
|
|
47
|
-
* Validates the configuration for required fields.
|
|
48
|
-
*/
|
|
49
|
-
static validate(config: RagConfig): void;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* BaseVectorProvider — Abstract base class for all vector database providers.
|
|
54
|
-
* Each provider (Pinecone, Milvus, Redis, etc.) must extend this class.
|
|
55
|
-
*/
|
|
56
|
-
declare abstract class BaseVectorProvider {
|
|
57
|
-
protected readonly config: VectorDBConfig;
|
|
58
|
-
protected readonly indexName: string;
|
|
59
|
-
constructor(config: VectorDBConfig);
|
|
60
|
-
/**
|
|
61
|
-
* Initialise the connection (create tables, verify index, etc.)
|
|
62
|
-
*/
|
|
63
|
-
abstract initialize(): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Insert or update a single vector + content pair.
|
|
66
|
-
*/
|
|
67
|
-
abstract upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Batch upsert for efficient ingestion of many documents.
|
|
70
|
-
*/
|
|
71
|
-
abstract batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
72
|
-
/**
|
|
73
|
-
* Find the top-K most similar vectors to the query vector.
|
|
74
|
-
*/
|
|
75
|
-
abstract query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
76
|
-
/**
|
|
77
|
-
* Delete a stored vector by ID.
|
|
78
|
-
*/
|
|
79
|
-
abstract delete(id: string, namespace?: string): Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
* Delete all vectors in a namespace (full data reset for a project).
|
|
82
|
-
*/
|
|
83
|
-
abstract deleteNamespace(namespace: string): Promise<void>;
|
|
84
|
-
/**
|
|
85
|
-
* Check if the underlying DB is reachable.
|
|
86
|
-
*/
|
|
87
|
-
abstract ping(): Promise<boolean>;
|
|
88
|
-
/**
|
|
89
|
-
* Gracefully close the connection.
|
|
90
|
-
*/
|
|
91
|
-
abstract disconnect(): Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* ProviderRegistry — dynamic provider loader for Vector DBs and LLMs.
|
|
96
|
-
*/
|
|
97
|
-
declare class ProviderRegistry {
|
|
98
|
-
private static vectorProviders;
|
|
99
|
-
/**
|
|
100
|
-
* Register a custom vector provider.
|
|
101
|
-
*/
|
|
102
|
-
static registerVectorProvider(name: string, providerClass: new (config: VectorDBConfig) => BaseVectorProvider): void;
|
|
103
|
-
/**
|
|
104
|
-
* Creates a vector database provider based on the configuration.
|
|
105
|
-
*/
|
|
106
|
-
static createVectorProvider(config: VectorDBConfig): Promise<BaseVectorProvider>;
|
|
107
|
-
/**
|
|
108
|
-
* Creates an LLM provider based on the configuration.
|
|
109
|
-
*/
|
|
110
|
-
static createLLMProvider(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): ILLMProvider;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* DocumentChunker — splits long text into overlapping chunks
|
|
115
|
-
* suitable for vector embedding and retrieval.
|
|
116
|
-
*
|
|
117
|
-
* Strategy: sentence-aware sliding window
|
|
118
|
-
* 1. Split on sentence boundaries
|
|
119
|
-
* 2. Accumulate sentences into chunks up to `chunkSize` characters
|
|
120
|
-
* 3. Carry over `chunkOverlap` characters from the previous chunk
|
|
121
|
-
*/
|
|
122
|
-
interface Chunk {
|
|
123
|
-
id: string;
|
|
124
|
-
content: string;
|
|
125
|
-
metadata?: Record<string, unknown>;
|
|
126
|
-
}
|
|
127
|
-
interface ChunkOptions {
|
|
128
|
-
/** Target chunk size in characters (default 1000) */
|
|
129
|
-
chunkSize?: number;
|
|
130
|
-
/** Overlap between consecutive chunks in characters (default 200) */
|
|
131
|
-
chunkOverlap?: number;
|
|
132
|
-
/** Source document identifier used as ID prefix */
|
|
133
|
-
docId?: string;
|
|
134
|
-
/** Extra metadata to attach to every chunk */
|
|
135
|
-
metadata?: Record<string, unknown>;
|
|
136
|
-
}
|
|
137
|
-
declare class DocumentChunker {
|
|
138
|
-
private readonly chunkSize;
|
|
139
|
-
private readonly chunkOverlap;
|
|
140
|
-
constructor(chunkSize?: number, chunkOverlap?: number);
|
|
141
|
-
/**
|
|
142
|
-
* Split a single text string into overlapping chunks.
|
|
143
|
-
*/
|
|
144
|
-
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
145
|
-
/**
|
|
146
|
-
* Chunk multiple documents at once.
|
|
147
|
-
*/
|
|
148
|
-
chunkMany(documents: Array<{
|
|
149
|
-
content: string;
|
|
150
|
-
docId?: string;
|
|
151
|
-
metadata?: Record<string, unknown>;
|
|
152
|
-
}>): Chunk[];
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { BaseVectorProvider as B, type Chunk as C, DocumentChunker as D, ProviderRegistry as P, VectorPlugin as V, type ChunkOptions as a, ConfigResolver as b };
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { e as RagConfig, C as ChatMessage, b as ChatResponse, d as IngestDocument, g as VectorDBConfig, f as UpsertDocument, V as VectorMatch, L as LLMConfig, c as EmbeddingConfig, I as ILLMProvider } from './Pipeline-Bo6CUCox.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* VectorPlugin — main orchestrator class.
|
|
5
|
-
* This is the primary interface for host applications.
|
|
6
|
-
*/
|
|
7
|
-
declare class VectorPlugin {
|
|
8
|
-
private config;
|
|
9
|
-
private pipeline;
|
|
10
|
-
/**
|
|
11
|
-
* Initializes the plugin with the host configuration.
|
|
12
|
-
* @param hostConfig - Configuration object passed from the host application.
|
|
13
|
-
*/
|
|
14
|
-
constructor(hostConfig?: Partial<RagConfig>);
|
|
15
|
-
/**
|
|
16
|
-
* Get the current resolved configuration.
|
|
17
|
-
*/
|
|
18
|
-
getConfig(): RagConfig;
|
|
19
|
-
/**
|
|
20
|
-
* Run a chat query.
|
|
21
|
-
*/
|
|
22
|
-
chat(message: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
|
|
23
|
-
/**
|
|
24
|
-
* Ingest documents into the vector database.
|
|
25
|
-
*/
|
|
26
|
-
ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
|
|
27
|
-
docId: string;
|
|
28
|
-
chunksIngested: number;
|
|
29
|
-
}>>;
|
|
30
|
-
/**
|
|
31
|
-
* Check the health of the connected providers.
|
|
32
|
-
*/
|
|
33
|
-
health(): Promise<Record<string, boolean>>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* ConfigResolver — validates and normalizes host configuration.
|
|
38
|
-
* It merges host-provided config with environment defaults.
|
|
39
|
-
*/
|
|
40
|
-
declare class ConfigResolver {
|
|
41
|
-
/**
|
|
42
|
-
* Resolves the final configuration by merging host-provided config with defaults.
|
|
43
|
-
* @param hostConfig - Partial configuration passed from the host application.
|
|
44
|
-
*/
|
|
45
|
-
static resolve(hostConfig?: Partial<RagConfig>): RagConfig;
|
|
46
|
-
/**
|
|
47
|
-
* Validates the configuration for required fields.
|
|
48
|
-
*/
|
|
49
|
-
static validate(config: RagConfig): void;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* BaseVectorProvider — Abstract base class for all vector database providers.
|
|
54
|
-
* Each provider (Pinecone, Milvus, Redis, etc.) must extend this class.
|
|
55
|
-
*/
|
|
56
|
-
declare abstract class BaseVectorProvider {
|
|
57
|
-
protected readonly config: VectorDBConfig;
|
|
58
|
-
protected readonly indexName: string;
|
|
59
|
-
constructor(config: VectorDBConfig);
|
|
60
|
-
/**
|
|
61
|
-
* Initialise the connection (create tables, verify index, etc.)
|
|
62
|
-
*/
|
|
63
|
-
abstract initialize(): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Insert or update a single vector + content pair.
|
|
66
|
-
*/
|
|
67
|
-
abstract upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Batch upsert for efficient ingestion of many documents.
|
|
70
|
-
*/
|
|
71
|
-
abstract batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
72
|
-
/**
|
|
73
|
-
* Find the top-K most similar vectors to the query vector.
|
|
74
|
-
*/
|
|
75
|
-
abstract query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
76
|
-
/**
|
|
77
|
-
* Delete a stored vector by ID.
|
|
78
|
-
*/
|
|
79
|
-
abstract delete(id: string, namespace?: string): Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
* Delete all vectors in a namespace (full data reset for a project).
|
|
82
|
-
*/
|
|
83
|
-
abstract deleteNamespace(namespace: string): Promise<void>;
|
|
84
|
-
/**
|
|
85
|
-
* Check if the underlying DB is reachable.
|
|
86
|
-
*/
|
|
87
|
-
abstract ping(): Promise<boolean>;
|
|
88
|
-
/**
|
|
89
|
-
* Gracefully close the connection.
|
|
90
|
-
*/
|
|
91
|
-
abstract disconnect(): Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* ProviderRegistry — dynamic provider loader for Vector DBs and LLMs.
|
|
96
|
-
*/
|
|
97
|
-
declare class ProviderRegistry {
|
|
98
|
-
private static vectorProviders;
|
|
99
|
-
/**
|
|
100
|
-
* Register a custom vector provider.
|
|
101
|
-
*/
|
|
102
|
-
static registerVectorProvider(name: string, providerClass: new (config: VectorDBConfig) => BaseVectorProvider): void;
|
|
103
|
-
/**
|
|
104
|
-
* Creates a vector database provider based on the configuration.
|
|
105
|
-
*/
|
|
106
|
-
static createVectorProvider(config: VectorDBConfig): Promise<BaseVectorProvider>;
|
|
107
|
-
/**
|
|
108
|
-
* Creates an LLM provider based on the configuration.
|
|
109
|
-
*/
|
|
110
|
-
static createLLMProvider(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): ILLMProvider;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* DocumentChunker — splits long text into overlapping chunks
|
|
115
|
-
* suitable for vector embedding and retrieval.
|
|
116
|
-
*
|
|
117
|
-
* Strategy: sentence-aware sliding window
|
|
118
|
-
* 1. Split on sentence boundaries
|
|
119
|
-
* 2. Accumulate sentences into chunks up to `chunkSize` characters
|
|
120
|
-
* 3. Carry over `chunkOverlap` characters from the previous chunk
|
|
121
|
-
*/
|
|
122
|
-
interface Chunk {
|
|
123
|
-
id: string;
|
|
124
|
-
content: string;
|
|
125
|
-
metadata?: Record<string, unknown>;
|
|
126
|
-
}
|
|
127
|
-
interface ChunkOptions {
|
|
128
|
-
/** Target chunk size in characters (default 1000) */
|
|
129
|
-
chunkSize?: number;
|
|
130
|
-
/** Overlap between consecutive chunks in characters (default 200) */
|
|
131
|
-
chunkOverlap?: number;
|
|
132
|
-
/** Source document identifier used as ID prefix */
|
|
133
|
-
docId?: string;
|
|
134
|
-
/** Extra metadata to attach to every chunk */
|
|
135
|
-
metadata?: Record<string, unknown>;
|
|
136
|
-
}
|
|
137
|
-
declare class DocumentChunker {
|
|
138
|
-
private readonly chunkSize;
|
|
139
|
-
private readonly chunkOverlap;
|
|
140
|
-
constructor(chunkSize?: number, chunkOverlap?: number);
|
|
141
|
-
/**
|
|
142
|
-
* Split a single text string into overlapping chunks.
|
|
143
|
-
*/
|
|
144
|
-
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
145
|
-
/**
|
|
146
|
-
* Chunk multiple documents at once.
|
|
147
|
-
*/
|
|
148
|
-
chunkMany(documents: Array<{
|
|
149
|
-
content: string;
|
|
150
|
-
docId?: string;
|
|
151
|
-
metadata?: Record<string, unknown>;
|
|
152
|
-
}>): Chunk[];
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { BaseVectorProvider as B, type Chunk as C, DocumentChunker as D, ProviderRegistry as P, VectorPlugin as V, type ChunkOptions as a, ConfigResolver as b };
|