@retrivora-ai/rag-engine 1.1.9 → 1.2.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/dist/{RagConfig-FyMB_UG6.d.mts → RagConfig-BOLOz0_O.d.mts} +52 -43
- package/dist/{RagConfig-FyMB_UG6.d.ts → RagConfig-BOLOz0_O.d.ts} +52 -43
- package/dist/{chunk-OCDCJUNE.mjs → chunk-GCPPRD2G.mjs} +70 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +70 -0
- package/dist/handlers/index.mjs +3 -1
- package/dist/{index-CYgr00ot.d.ts → index-64BDupW3.d.mts} +14 -2
- package/dist/{index-D-lfcqlL.d.mts → index-DbtE8wLM.d.ts} +14 -2
- package/dist/index.d.mts +4 -14
- package/dist/index.d.ts +4 -14
- package/dist/index.js +83 -3
- package/dist/index.mjs +83 -3
- package/dist/server.d.mts +7 -3
- package/dist/server.d.ts +7 -3
- package/dist/server.js +51 -0
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
- package/src/app/api/suggestions/route.ts +4 -0
- package/src/components/ChatWidget.tsx +2 -1
- package/src/components/ChatWindow.tsx +67 -2
- package/src/components/MessageBubble.tsx +60 -17
- package/src/components/ProductCard.tsx +1 -9
- package/src/components/ProductCarousel.tsx +2 -1
- package/src/core/Pipeline.ts +55 -0
- package/src/core/VectorPlugin.ts +7 -0
- package/src/handlers/index.ts +30 -0
- package/src/types/index.ts +14 -0
|
@@ -1,3 +1,54 @@
|
|
|
1
|
+
interface VectorMatch {
|
|
2
|
+
id: string | number;
|
|
3
|
+
score: number;
|
|
4
|
+
content: string;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface UpsertDocument {
|
|
8
|
+
id: string | number;
|
|
9
|
+
vector: number[];
|
|
10
|
+
content: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface IngestDocument {
|
|
14
|
+
docId: string | number;
|
|
15
|
+
content: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
interface ChatResponse {
|
|
19
|
+
reply: string;
|
|
20
|
+
sources: VectorMatch[];
|
|
21
|
+
graphData?: GraphSearchResult;
|
|
22
|
+
}
|
|
23
|
+
interface GraphNode {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
properties?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
interface Edge {
|
|
29
|
+
source: string;
|
|
30
|
+
target: string;
|
|
31
|
+
type: string;
|
|
32
|
+
properties?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
interface GraphSearchResult {
|
|
35
|
+
nodes: GraphNode[];
|
|
36
|
+
edges: Edge[];
|
|
37
|
+
}
|
|
38
|
+
interface RetrievalResult {
|
|
39
|
+
sources: VectorMatch[];
|
|
40
|
+
graphData?: GraphSearchResult;
|
|
41
|
+
}
|
|
42
|
+
interface Product {
|
|
43
|
+
id: string | number;
|
|
44
|
+
name: string;
|
|
45
|
+
brand?: string;
|
|
46
|
+
price?: string | number;
|
|
47
|
+
image?: string;
|
|
48
|
+
link?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
1
52
|
/**
|
|
2
53
|
* Generic LLM Provider interface.
|
|
3
54
|
* Covers both chat completion and embedding generation so a single
|
|
@@ -55,48 +106,6 @@ interface ILLMProvider {
|
|
|
55
106
|
ping(): Promise<boolean>;
|
|
56
107
|
}
|
|
57
108
|
|
|
58
|
-
interface VectorMatch {
|
|
59
|
-
id: string | number;
|
|
60
|
-
score: number;
|
|
61
|
-
content: string;
|
|
62
|
-
metadata?: Record<string, unknown>;
|
|
63
|
-
}
|
|
64
|
-
interface UpsertDocument {
|
|
65
|
-
id: string | number;
|
|
66
|
-
vector: number[];
|
|
67
|
-
content: string;
|
|
68
|
-
metadata?: Record<string, unknown>;
|
|
69
|
-
}
|
|
70
|
-
interface IngestDocument {
|
|
71
|
-
docId: string | number;
|
|
72
|
-
content: string;
|
|
73
|
-
metadata?: Record<string, unknown>;
|
|
74
|
-
}
|
|
75
|
-
interface ChatResponse {
|
|
76
|
-
reply: string;
|
|
77
|
-
sources: VectorMatch[];
|
|
78
|
-
graphData?: GraphSearchResult;
|
|
79
|
-
}
|
|
80
|
-
interface GraphNode {
|
|
81
|
-
id: string;
|
|
82
|
-
label: string;
|
|
83
|
-
properties?: Record<string, unknown>;
|
|
84
|
-
}
|
|
85
|
-
interface Edge {
|
|
86
|
-
source: string;
|
|
87
|
-
target: string;
|
|
88
|
-
type: string;
|
|
89
|
-
properties?: Record<string, unknown>;
|
|
90
|
-
}
|
|
91
|
-
interface GraphSearchResult {
|
|
92
|
-
nodes: GraphNode[];
|
|
93
|
-
edges: Edge[];
|
|
94
|
-
}
|
|
95
|
-
interface RetrievalResult {
|
|
96
|
-
sources: VectorMatch[];
|
|
97
|
-
graphData?: GraphSearchResult;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
109
|
/**
|
|
101
110
|
* constants.ts — Centralized definitions of acceptable configuration values.
|
|
102
111
|
*
|
|
@@ -271,4 +280,4 @@ interface RagConfig {
|
|
|
271
280
|
graphDb?: GraphDBConfig;
|
|
272
281
|
}
|
|
273
282
|
|
|
274
|
-
export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, ChatOptions as a, ChatResponse as b, EmbeddingConfig as c, EmbeddingProvider as d, IngestDocument as e, LLMProvider as f, RagConfig as g, UpsertDocument as h, VectorDBConfig as i, VectorDBProvider as j, RetrievalResult as k, GraphNode as l, Edge as m, GraphSearchResult as n };
|
|
283
|
+
export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, Product as P, RAGConfig as R, UIConfig as U, VectorMatch as V, ChatOptions as a, ChatResponse as b, EmbeddingConfig as c, EmbeddingProvider as d, IngestDocument as e, LLMProvider as f, RagConfig as g, UpsertDocument as h, VectorDBConfig as i, VectorDBProvider as j, RetrievalResult as k, GraphNode as l, Edge as m, GraphSearchResult as n };
|
|
@@ -1,3 +1,54 @@
|
|
|
1
|
+
interface VectorMatch {
|
|
2
|
+
id: string | number;
|
|
3
|
+
score: number;
|
|
4
|
+
content: string;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface UpsertDocument {
|
|
8
|
+
id: string | number;
|
|
9
|
+
vector: number[];
|
|
10
|
+
content: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface IngestDocument {
|
|
14
|
+
docId: string | number;
|
|
15
|
+
content: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
interface ChatResponse {
|
|
19
|
+
reply: string;
|
|
20
|
+
sources: VectorMatch[];
|
|
21
|
+
graphData?: GraphSearchResult;
|
|
22
|
+
}
|
|
23
|
+
interface GraphNode {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
properties?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
interface Edge {
|
|
29
|
+
source: string;
|
|
30
|
+
target: string;
|
|
31
|
+
type: string;
|
|
32
|
+
properties?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
interface GraphSearchResult {
|
|
35
|
+
nodes: GraphNode[];
|
|
36
|
+
edges: Edge[];
|
|
37
|
+
}
|
|
38
|
+
interface RetrievalResult {
|
|
39
|
+
sources: VectorMatch[];
|
|
40
|
+
graphData?: GraphSearchResult;
|
|
41
|
+
}
|
|
42
|
+
interface Product {
|
|
43
|
+
id: string | number;
|
|
44
|
+
name: string;
|
|
45
|
+
brand?: string;
|
|
46
|
+
price?: string | number;
|
|
47
|
+
image?: string;
|
|
48
|
+
link?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
1
52
|
/**
|
|
2
53
|
* Generic LLM Provider interface.
|
|
3
54
|
* Covers both chat completion and embedding generation so a single
|
|
@@ -55,48 +106,6 @@ interface ILLMProvider {
|
|
|
55
106
|
ping(): Promise<boolean>;
|
|
56
107
|
}
|
|
57
108
|
|
|
58
|
-
interface VectorMatch {
|
|
59
|
-
id: string | number;
|
|
60
|
-
score: number;
|
|
61
|
-
content: string;
|
|
62
|
-
metadata?: Record<string, unknown>;
|
|
63
|
-
}
|
|
64
|
-
interface UpsertDocument {
|
|
65
|
-
id: string | number;
|
|
66
|
-
vector: number[];
|
|
67
|
-
content: string;
|
|
68
|
-
metadata?: Record<string, unknown>;
|
|
69
|
-
}
|
|
70
|
-
interface IngestDocument {
|
|
71
|
-
docId: string | number;
|
|
72
|
-
content: string;
|
|
73
|
-
metadata?: Record<string, unknown>;
|
|
74
|
-
}
|
|
75
|
-
interface ChatResponse {
|
|
76
|
-
reply: string;
|
|
77
|
-
sources: VectorMatch[];
|
|
78
|
-
graphData?: GraphSearchResult;
|
|
79
|
-
}
|
|
80
|
-
interface GraphNode {
|
|
81
|
-
id: string;
|
|
82
|
-
label: string;
|
|
83
|
-
properties?: Record<string, unknown>;
|
|
84
|
-
}
|
|
85
|
-
interface Edge {
|
|
86
|
-
source: string;
|
|
87
|
-
target: string;
|
|
88
|
-
type: string;
|
|
89
|
-
properties?: Record<string, unknown>;
|
|
90
|
-
}
|
|
91
|
-
interface GraphSearchResult {
|
|
92
|
-
nodes: GraphNode[];
|
|
93
|
-
edges: Edge[];
|
|
94
|
-
}
|
|
95
|
-
interface RetrievalResult {
|
|
96
|
-
sources: VectorMatch[];
|
|
97
|
-
graphData?: GraphSearchResult;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
109
|
/**
|
|
101
110
|
* constants.ts — Centralized definitions of acceptable configuration values.
|
|
102
111
|
*
|
|
@@ -271,4 +280,4 @@ interface RagConfig {
|
|
|
271
280
|
graphDb?: GraphDBConfig;
|
|
272
281
|
}
|
|
273
282
|
|
|
274
|
-
export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, ChatOptions as a, ChatResponse as b, EmbeddingConfig as c, EmbeddingProvider as d, IngestDocument as e, LLMProvider as f, RagConfig as g, UpsertDocument as h, VectorDBConfig as i, VectorDBProvider as j, RetrievalResult as k, GraphNode as l, Edge as m, GraphSearchResult as n };
|
|
283
|
+
export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, Product as P, RAGConfig as R, UIConfig as U, VectorMatch as V, ChatOptions as a, ChatResponse as b, EmbeddingConfig as c, EmbeddingProvider as d, IngestDocument as e, LLMProvider as f, RagConfig as g, UpsertDocument as h, VectorDBConfig as i, VectorDBProvider as j, RetrievalResult as k, GraphNode as l, Edge as m, GraphSearchResult as n };
|
|
@@ -2523,6 +2523,50 @@ Optimized Search Query:`;
|
|
|
2523
2523
|
);
|
|
2524
2524
|
return rewrite.trim() || question;
|
|
2525
2525
|
}
|
|
2526
|
+
/**
|
|
2527
|
+
* Generate 3-5 short, relevant questions based on the vector database content.
|
|
2528
|
+
*/
|
|
2529
|
+
async getSuggestions(query, namespace) {
|
|
2530
|
+
if (!query || query.trim().length < 3) {
|
|
2531
|
+
return [];
|
|
2532
|
+
}
|
|
2533
|
+
await this.initialize();
|
|
2534
|
+
const ns = namespace != null ? namespace : this.config.projectId;
|
|
2535
|
+
try {
|
|
2536
|
+
const { sources } = await this.retrieve(query, { namespace: ns, topK: 3 });
|
|
2537
|
+
if (sources.length === 0) {
|
|
2538
|
+
return [];
|
|
2539
|
+
}
|
|
2540
|
+
const context = sources.map((s) => s.content).join("\n\n---\n\n");
|
|
2541
|
+
const prompt = `
|
|
2542
|
+
Based on the following snippets from a document, what are 3 short, relevant questions a user might ask?
|
|
2543
|
+
Focus on questions that can be answered by the context.
|
|
2544
|
+
Keep each question under 10 words and make them very specific to the content.
|
|
2545
|
+
Return ONLY a JSON array of strings like ["Question 1", "Question 2", "Question 3"].
|
|
2546
|
+
|
|
2547
|
+
Context:
|
|
2548
|
+
${context}
|
|
2549
|
+
|
|
2550
|
+
Suggestions:`;
|
|
2551
|
+
const response = await this.llmProvider.chat(
|
|
2552
|
+
[
|
|
2553
|
+
{ role: "system", content: "You are a helpful assistant that generates search suggestions." },
|
|
2554
|
+
{ role: "user", content: prompt }
|
|
2555
|
+
],
|
|
2556
|
+
""
|
|
2557
|
+
);
|
|
2558
|
+
const match = response.match(/\[[\s\S]*\]/);
|
|
2559
|
+
if (match) {
|
|
2560
|
+
const suggestions = JSON.parse(match[0]);
|
|
2561
|
+
if (Array.isArray(suggestions)) {
|
|
2562
|
+
return suggestions.map((s) => String(s)).slice(0, 3);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
} catch (error) {
|
|
2566
|
+
console.error("[Pipeline] Failed to generate suggestions:", error);
|
|
2567
|
+
}
|
|
2568
|
+
return [];
|
|
2569
|
+
}
|
|
2526
2570
|
};
|
|
2527
2571
|
|
|
2528
2572
|
// src/core/ProviderHealthCheck.ts
|
|
@@ -2677,6 +2721,13 @@ var VectorPlugin = class {
|
|
|
2677
2721
|
await this.validationPromise;
|
|
2678
2722
|
return this.pipeline.ingest(documents, namespace);
|
|
2679
2723
|
}
|
|
2724
|
+
/**
|
|
2725
|
+
* Get auto-suggestions based on a query prefix.
|
|
2726
|
+
*/
|
|
2727
|
+
async getSuggestions(query, namespace) {
|
|
2728
|
+
await this.validationPromise;
|
|
2729
|
+
return this.pipeline.getSuggestions(query, namespace);
|
|
2730
|
+
}
|
|
2680
2731
|
};
|
|
2681
2732
|
|
|
2682
2733
|
// src/utils/DocumentParser.ts
|
|
@@ -2906,6 +2957,23 @@ function createUploadHandler(configOrPlugin) {
|
|
|
2906
2957
|
}
|
|
2907
2958
|
};
|
|
2908
2959
|
}
|
|
2960
|
+
function createSuggestionsHandler(configOrPlugin) {
|
|
2961
|
+
const plugin = configOrPlugin instanceof VectorPlugin ? configOrPlugin : new VectorPlugin(configOrPlugin);
|
|
2962
|
+
return async function POST(req) {
|
|
2963
|
+
try {
|
|
2964
|
+
const body = await req.json();
|
|
2965
|
+
const { query, namespace } = body;
|
|
2966
|
+
if (typeof query !== "string") {
|
|
2967
|
+
return NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
2968
|
+
}
|
|
2969
|
+
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
2970
|
+
return NextResponse.json({ suggestions });
|
|
2971
|
+
} catch (err) {
|
|
2972
|
+
const message = err instanceof Error ? err.message : "Internal server error";
|
|
2973
|
+
return NextResponse.json({ error: message }, { status: 500 });
|
|
2974
|
+
}
|
|
2975
|
+
};
|
|
2976
|
+
}
|
|
2909
2977
|
|
|
2910
2978
|
export {
|
|
2911
2979
|
getRagConfig,
|
|
@@ -2935,5 +3003,6 @@ export {
|
|
|
2935
3003
|
createStreamHandler,
|
|
2936
3004
|
createIngestHandler,
|
|
2937
3005
|
createHealthHandler,
|
|
2938
|
-
createUploadHandler
|
|
3006
|
+
createUploadHandler,
|
|
3007
|
+
createSuggestionsHandler
|
|
2939
3008
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import '../RagConfig-
|
|
2
|
-
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-
|
|
1
|
+
import '../RagConfig-BOLOz0_O.mjs';
|
|
2
|
+
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-64BDupW3.mjs';
|
|
3
3
|
import 'next/server';
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import '../RagConfig-
|
|
2
|
-
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-
|
|
1
|
+
import '../RagConfig-BOLOz0_O.js';
|
|
2
|
+
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-DbtE8wLM.js';
|
|
3
3
|
import 'next/server';
|
package/dist/handlers/index.js
CHANGED
|
@@ -1612,6 +1612,7 @@ __export(handlers_exports, {
|
|
|
1612
1612
|
createHealthHandler: () => createHealthHandler,
|
|
1613
1613
|
createIngestHandler: () => createIngestHandler,
|
|
1614
1614
|
createStreamHandler: () => createStreamHandler,
|
|
1615
|
+
createSuggestionsHandler: () => createSuggestionsHandler,
|
|
1615
1616
|
createUploadHandler: () => createUploadHandler,
|
|
1616
1617
|
sseErrorFrame: () => sseErrorFrame,
|
|
1617
1618
|
sseFrame: () => sseFrame,
|
|
@@ -4085,6 +4086,50 @@ Optimized Search Query:`;
|
|
|
4085
4086
|
);
|
|
4086
4087
|
return rewrite.trim() || question;
|
|
4087
4088
|
}
|
|
4089
|
+
/**
|
|
4090
|
+
* Generate 3-5 short, relevant questions based on the vector database content.
|
|
4091
|
+
*/
|
|
4092
|
+
async getSuggestions(query, namespace) {
|
|
4093
|
+
if (!query || query.trim().length < 3) {
|
|
4094
|
+
return [];
|
|
4095
|
+
}
|
|
4096
|
+
await this.initialize();
|
|
4097
|
+
const ns = namespace != null ? namespace : this.config.projectId;
|
|
4098
|
+
try {
|
|
4099
|
+
const { sources } = await this.retrieve(query, { namespace: ns, topK: 3 });
|
|
4100
|
+
if (sources.length === 0) {
|
|
4101
|
+
return [];
|
|
4102
|
+
}
|
|
4103
|
+
const context = sources.map((s) => s.content).join("\n\n---\n\n");
|
|
4104
|
+
const prompt = `
|
|
4105
|
+
Based on the following snippets from a document, what are 3 short, relevant questions a user might ask?
|
|
4106
|
+
Focus on questions that can be answered by the context.
|
|
4107
|
+
Keep each question under 10 words and make them very specific to the content.
|
|
4108
|
+
Return ONLY a JSON array of strings like ["Question 1", "Question 2", "Question 3"].
|
|
4109
|
+
|
|
4110
|
+
Context:
|
|
4111
|
+
${context}
|
|
4112
|
+
|
|
4113
|
+
Suggestions:`;
|
|
4114
|
+
const response = await this.llmProvider.chat(
|
|
4115
|
+
[
|
|
4116
|
+
{ role: "system", content: "You are a helpful assistant that generates search suggestions." },
|
|
4117
|
+
{ role: "user", content: prompt }
|
|
4118
|
+
],
|
|
4119
|
+
""
|
|
4120
|
+
);
|
|
4121
|
+
const match = response.match(/\[[\s\S]*\]/);
|
|
4122
|
+
if (match) {
|
|
4123
|
+
const suggestions = JSON.parse(match[0]);
|
|
4124
|
+
if (Array.isArray(suggestions)) {
|
|
4125
|
+
return suggestions.map((s) => String(s)).slice(0, 3);
|
|
4126
|
+
}
|
|
4127
|
+
}
|
|
4128
|
+
} catch (error) {
|
|
4129
|
+
console.error("[Pipeline] Failed to generate suggestions:", error);
|
|
4130
|
+
}
|
|
4131
|
+
return [];
|
|
4132
|
+
}
|
|
4088
4133
|
};
|
|
4089
4134
|
|
|
4090
4135
|
// src/core/ProviderHealthCheck.ts
|
|
@@ -4239,6 +4284,13 @@ var VectorPlugin = class {
|
|
|
4239
4284
|
await this.validationPromise;
|
|
4240
4285
|
return this.pipeline.ingest(documents, namespace);
|
|
4241
4286
|
}
|
|
4287
|
+
/**
|
|
4288
|
+
* Get auto-suggestions based on a query prefix.
|
|
4289
|
+
*/
|
|
4290
|
+
async getSuggestions(query, namespace) {
|
|
4291
|
+
await this.validationPromise;
|
|
4292
|
+
return this.pipeline.getSuggestions(query, namespace);
|
|
4293
|
+
}
|
|
4242
4294
|
};
|
|
4243
4295
|
|
|
4244
4296
|
// src/utils/DocumentParser.ts
|
|
@@ -4468,12 +4520,30 @@ function createUploadHandler(configOrPlugin) {
|
|
|
4468
4520
|
}
|
|
4469
4521
|
};
|
|
4470
4522
|
}
|
|
4523
|
+
function createSuggestionsHandler(configOrPlugin) {
|
|
4524
|
+
const plugin = configOrPlugin instanceof VectorPlugin ? configOrPlugin : new VectorPlugin(configOrPlugin);
|
|
4525
|
+
return async function POST(req) {
|
|
4526
|
+
try {
|
|
4527
|
+
const body = await req.json();
|
|
4528
|
+
const { query, namespace } = body;
|
|
4529
|
+
if (typeof query !== "string") {
|
|
4530
|
+
return import_server.NextResponse.json({ error: "query is required" }, { status: 400 });
|
|
4531
|
+
}
|
|
4532
|
+
const suggestions = await plugin.getSuggestions(query, namespace);
|
|
4533
|
+
return import_server.NextResponse.json({ suggestions });
|
|
4534
|
+
} catch (err) {
|
|
4535
|
+
const message = err instanceof Error ? err.message : "Internal server error";
|
|
4536
|
+
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
4537
|
+
}
|
|
4538
|
+
};
|
|
4539
|
+
}
|
|
4471
4540
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4472
4541
|
0 && (module.exports = {
|
|
4473
4542
|
createChatHandler,
|
|
4474
4543
|
createHealthHandler,
|
|
4475
4544
|
createIngestHandler,
|
|
4476
4545
|
createStreamHandler,
|
|
4546
|
+
createSuggestionsHandler,
|
|
4477
4547
|
createUploadHandler,
|
|
4478
4548
|
sseErrorFrame,
|
|
4479
4549
|
sseFrame,
|
package/dist/handlers/index.mjs
CHANGED
|
@@ -3,12 +3,13 @@ import {
|
|
|
3
3
|
createHealthHandler,
|
|
4
4
|
createIngestHandler,
|
|
5
5
|
createStreamHandler,
|
|
6
|
+
createSuggestionsHandler,
|
|
6
7
|
createUploadHandler,
|
|
7
8
|
sseErrorFrame,
|
|
8
9
|
sseFrame,
|
|
9
10
|
sseMetaFrame,
|
|
10
11
|
sseTextFrame
|
|
11
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-GCPPRD2G.mjs";
|
|
12
13
|
import "../chunk-YLTMFW4M.mjs";
|
|
13
14
|
import "../chunk-X4TOT24V.mjs";
|
|
14
15
|
export {
|
|
@@ -16,6 +17,7 @@ export {
|
|
|
16
17
|
createHealthHandler,
|
|
17
18
|
createIngestHandler,
|
|
18
19
|
createStreamHandler,
|
|
20
|
+
createSuggestionsHandler,
|
|
19
21
|
createUploadHandler,
|
|
20
22
|
sseErrorFrame,
|
|
21
23
|
sseFrame,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-
|
|
1
|
+
import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-BOLOz0_O.mjs';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
|
|
4
4
|
interface ValidationError {
|
|
@@ -112,6 +112,10 @@ declare class VectorPlugin {
|
|
|
112
112
|
docId: string | number;
|
|
113
113
|
chunksIngested: number;
|
|
114
114
|
}>>;
|
|
115
|
+
/**
|
|
116
|
+
* Get auto-suggestions based on a query prefix.
|
|
117
|
+
*/
|
|
118
|
+
getSuggestions(query: string, namespace?: string): Promise<string[]>;
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
/**
|
|
@@ -202,5 +206,13 @@ declare function createUploadHandler(configOrPlugin?: Partial<RagConfig> | Vecto
|
|
|
202
206
|
chunksIngested: number;
|
|
203
207
|
}[];
|
|
204
208
|
}>>;
|
|
209
|
+
/**
|
|
210
|
+
* createSuggestionsHandler — factory for the auto-suggestions endpoint.
|
|
211
|
+
*/
|
|
212
|
+
declare function createSuggestionsHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin): (req: NextRequest) => Promise<NextResponse<{
|
|
213
|
+
error: string;
|
|
214
|
+
}> | NextResponse<{
|
|
215
|
+
suggestions: string[];
|
|
216
|
+
}>>;
|
|
205
217
|
|
|
206
|
-
export { ConfigValidator as C, type HealthCheckResult as H, type IProviderValidator as I, type ValidationError as V, type IProviderHealthChecker as a, VectorPlugin as b, createChatHandler as c, createHealthHandler as d, createIngestHandler as e, createStreamHandler as f, createUploadHandler as g, sseFrame as h, sseMetaFrame as i, sseTextFrame as j, sseErrorFrame as s };
|
|
218
|
+
export { ConfigValidator as C, type HealthCheckResult as H, type IProviderValidator as I, type ValidationError as V, type IProviderHealthChecker as a, VectorPlugin as b, createChatHandler as c, createHealthHandler as d, createIngestHandler as e, createStreamHandler as f, createUploadHandler as g, sseFrame as h, sseMetaFrame as i, sseTextFrame as j, createSuggestionsHandler as k, sseErrorFrame as s };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-
|
|
1
|
+
import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-BOLOz0_O.js';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
|
|
4
4
|
interface ValidationError {
|
|
@@ -112,6 +112,10 @@ declare class VectorPlugin {
|
|
|
112
112
|
docId: string | number;
|
|
113
113
|
chunksIngested: number;
|
|
114
114
|
}>>;
|
|
115
|
+
/**
|
|
116
|
+
* Get auto-suggestions based on a query prefix.
|
|
117
|
+
*/
|
|
118
|
+
getSuggestions(query: string, namespace?: string): Promise<string[]>;
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
/**
|
|
@@ -202,5 +206,13 @@ declare function createUploadHandler(configOrPlugin?: Partial<RagConfig> | Vecto
|
|
|
202
206
|
chunksIngested: number;
|
|
203
207
|
}[];
|
|
204
208
|
}>>;
|
|
209
|
+
/**
|
|
210
|
+
* createSuggestionsHandler — factory for the auto-suggestions endpoint.
|
|
211
|
+
*/
|
|
212
|
+
declare function createSuggestionsHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin): (req: NextRequest) => Promise<NextResponse<{
|
|
213
|
+
error: string;
|
|
214
|
+
}> | NextResponse<{
|
|
215
|
+
suggestions: string[];
|
|
216
|
+
}>>;
|
|
205
217
|
|
|
206
|
-
export { ConfigValidator as C, type HealthCheckResult as H, type IProviderValidator as I, type ValidationError as V, type IProviderHealthChecker as a, VectorPlugin as b, createChatHandler as c, createHealthHandler as d, createIngestHandler as e, createStreamHandler as f, createUploadHandler as g, sseFrame as h, sseMetaFrame as i, sseTextFrame as j, sseErrorFrame as s };
|
|
218
|
+
export { ConfigValidator as C, type HealthCheckResult as H, type IProviderValidator as I, type ValidationError as V, type IProviderHealthChecker as a, VectorPlugin as b, createChatHandler as c, createHealthHandler as d, createIngestHandler as e, createStreamHandler as f, createUploadHandler as g, sseFrame as h, sseMetaFrame as i, sseTextFrame as j, createSuggestionsHandler as k, sseErrorFrame as s };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React$1, { ReactNode } from 'react';
|
|
2
|
-
import { C as ChatMessage, V as VectorMatch, U as UIConfig } from './RagConfig-
|
|
3
|
-
export { a as ChatOptions, b as ChatResponse, E as EmbedOptions, c as EmbeddingConfig, d as EmbeddingProvider, I as ILLMProvider, e as IngestDocument, L as LLMConfig, f as LLMProvider, R as RAGConfig, g as RagConfig, h as UpsertDocument, i as VectorDBConfig, j as VectorDBProvider } from './RagConfig-
|
|
2
|
+
import { P as Product, C as ChatMessage, V as VectorMatch, U as UIConfig } from './RagConfig-BOLOz0_O.mjs';
|
|
3
|
+
export { a as ChatOptions, b as ChatResponse, E as EmbedOptions, c as EmbeddingConfig, d as EmbeddingProvider, I as ILLMProvider, e as IngestDocument, L as LLMConfig, f as LLMProvider, R as RAGConfig, g as RagConfig, h as UpsertDocument, i as VectorDBConfig, j as VectorDBProvider } from './RagConfig-BOLOz0_O.mjs';
|
|
4
4
|
export { C as Chunk, a as ChunkOptions } from './DocumentChunker-Dh9TvmGG.mjs';
|
|
5
5
|
|
|
6
6
|
interface ChatWidgetProps {
|
|
7
7
|
/** Position of the floating button. Defaults to bottom-right. */
|
|
8
8
|
position?: 'bottom-right' | 'bottom-left';
|
|
9
9
|
/** Called when the user clicks 'Add to Cart' on a product */
|
|
10
|
-
onAddToCart?: (product:
|
|
10
|
+
onAddToCart?: (product: Product) => void;
|
|
11
11
|
}
|
|
12
12
|
declare function ChatWidget({ position, onAddToCart }: ChatWidgetProps): React$1.JSX.Element | null;
|
|
13
13
|
|
|
@@ -31,7 +31,7 @@ interface ChatWindowProps {
|
|
|
31
31
|
/** Whether the window is currently maximized */
|
|
32
32
|
isMaximized?: boolean;
|
|
33
33
|
/** Called when the user clicks 'Add to Cart' on a product */
|
|
34
|
-
onAddToCart?: (product:
|
|
34
|
+
onAddToCart?: (product: Product) => void;
|
|
35
35
|
}
|
|
36
36
|
declare function ChatWindow({ className, style, onClose, showClose, onResizeStart, onResetResize, isResized, onMaximize, isMaximized, onAddToCart }: ChatWindowProps): React$1.JSX.Element;
|
|
37
37
|
|
|
@@ -45,16 +45,6 @@ interface DocumentUploadProps {
|
|
|
45
45
|
}
|
|
46
46
|
declare function DocumentUpload({ namespace, onUploadComplete, className }: DocumentUploadProps): React$1.JSX.Element;
|
|
47
47
|
|
|
48
|
-
interface Product {
|
|
49
|
-
id: string | number;
|
|
50
|
-
name: string;
|
|
51
|
-
brand?: string;
|
|
52
|
-
price?: string | number;
|
|
53
|
-
image?: string;
|
|
54
|
-
link?: string;
|
|
55
|
-
description?: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
48
|
interface MessageBubbleProps {
|
|
59
49
|
message: ChatMessage;
|
|
60
50
|
sources?: VectorMatch[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React$1, { ReactNode } from 'react';
|
|
2
|
-
import { C as ChatMessage, V as VectorMatch, U as UIConfig } from './RagConfig-
|
|
3
|
-
export { a as ChatOptions, b as ChatResponse, E as EmbedOptions, c as EmbeddingConfig, d as EmbeddingProvider, I as ILLMProvider, e as IngestDocument, L as LLMConfig, f as LLMProvider, R as RAGConfig, g as RagConfig, h as UpsertDocument, i as VectorDBConfig, j as VectorDBProvider } from './RagConfig-
|
|
2
|
+
import { P as Product, C as ChatMessage, V as VectorMatch, U as UIConfig } from './RagConfig-BOLOz0_O.js';
|
|
3
|
+
export { a as ChatOptions, b as ChatResponse, E as EmbedOptions, c as EmbeddingConfig, d as EmbeddingProvider, I as ILLMProvider, e as IngestDocument, L as LLMConfig, f as LLMProvider, R as RAGConfig, g as RagConfig, h as UpsertDocument, i as VectorDBConfig, j as VectorDBProvider } from './RagConfig-BOLOz0_O.js';
|
|
4
4
|
export { C as Chunk, a as ChunkOptions } from './DocumentChunker-Dh9TvmGG.js';
|
|
5
5
|
|
|
6
6
|
interface ChatWidgetProps {
|
|
7
7
|
/** Position of the floating button. Defaults to bottom-right. */
|
|
8
8
|
position?: 'bottom-right' | 'bottom-left';
|
|
9
9
|
/** Called when the user clicks 'Add to Cart' on a product */
|
|
10
|
-
onAddToCart?: (product:
|
|
10
|
+
onAddToCart?: (product: Product) => void;
|
|
11
11
|
}
|
|
12
12
|
declare function ChatWidget({ position, onAddToCart }: ChatWidgetProps): React$1.JSX.Element | null;
|
|
13
13
|
|
|
@@ -31,7 +31,7 @@ interface ChatWindowProps {
|
|
|
31
31
|
/** Whether the window is currently maximized */
|
|
32
32
|
isMaximized?: boolean;
|
|
33
33
|
/** Called when the user clicks 'Add to Cart' on a product */
|
|
34
|
-
onAddToCart?: (product:
|
|
34
|
+
onAddToCart?: (product: Product) => void;
|
|
35
35
|
}
|
|
36
36
|
declare function ChatWindow({ className, style, onClose, showClose, onResizeStart, onResetResize, isResized, onMaximize, isMaximized, onAddToCart }: ChatWindowProps): React$1.JSX.Element;
|
|
37
37
|
|
|
@@ -45,16 +45,6 @@ interface DocumentUploadProps {
|
|
|
45
45
|
}
|
|
46
46
|
declare function DocumentUpload({ namespace, onUploadComplete, className }: DocumentUploadProps): React$1.JSX.Element;
|
|
47
47
|
|
|
48
|
-
interface Product {
|
|
49
|
-
id: string | number;
|
|
50
|
-
name: string;
|
|
51
|
-
brand?: string;
|
|
52
|
-
price?: string | number;
|
|
53
|
-
image?: string;
|
|
54
|
-
link?: string;
|
|
55
|
-
description?: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
48
|
interface MessageBubbleProps {
|
|
59
49
|
message: ChatMessage;
|
|
60
50
|
sources?: VectorMatch[];
|