@elqnt/kg 2.1.1 → 3.0.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/README.md +357 -39
- package/dist/api/index.d.mts +248 -1
- package/dist/api/index.d.ts +248 -1
- package/dist/api/index.js +2 -2
- package/dist/api/index.mjs +1 -1
- package/dist/api/server.d.mts +219 -0
- package/dist/api/server.d.ts +219 -0
- package/dist/api/server.js +442 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/server.mjs +442 -0
- package/dist/api/server.mjs.map +1 -0
- package/dist/{chunk-4XIW5GLO.js → chunk-2TJCYLTP.js} +63 -68
- package/dist/chunk-2TJCYLTP.js.map +1 -0
- package/dist/chunk-7RW5MHP5.js +497 -0
- package/dist/chunk-7RW5MHP5.js.map +1 -0
- package/dist/chunk-ADIKUMMI.js +238 -0
- package/dist/chunk-ADIKUMMI.js.map +1 -0
- package/dist/chunk-CAXPQTKI.mjs +238 -0
- package/dist/chunk-CAXPQTKI.mjs.map +1 -0
- package/dist/{chunk-3AS6C7FW.mjs → chunk-HCDFJCQL.mjs} +62 -67
- package/dist/chunk-HCDFJCQL.mjs.map +1 -0
- package/dist/chunk-JZ7UXVRW.mjs +497 -0
- package/dist/chunk-JZ7UXVRW.mjs.map +1 -0
- package/dist/hooks/index.d.mts +109 -4
- package/dist/hooks/index.d.ts +109 -4
- package/dist/hooks/index.js +9 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +10 -4
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +21 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -4
- package/dist/index.mjs.map +1 -1
- package/dist/utils/index.d.mts +277 -0
- package/dist/utils/index.d.ts +277 -0
- package/dist/utils/index.js +44 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +44 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +15 -5
- package/dist/chunk-3AS6C7FW.mjs.map +0 -1
- package/dist/chunk-4XIW5GLO.js.map +0 -1
- package/dist/chunk-7HNJUCVW.js +0 -577
- package/dist/chunk-7HNJUCVW.js.map +0 -1
- package/dist/chunk-EW3NQGUZ.mjs +0 -577
- package/dist/chunk-EW3NQGUZ.mjs.map +0 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { KGFieldQueryOperator, KGQuery, KGEdgeQuery, KGFieldQuery } from '../models/kg.mjs';
|
|
2
|
+
export { KGFieldQueryOperatorArrayContains, KGFieldQueryOperatorEqual, KGFieldQueryOperatorGreater, KGFieldQueryOperatorGreaterOrEqual, KGFieldQueryOperatorIn, KGFieldQueryOperatorLess, KGFieldQueryOperatorLessOrEqual, KGFieldQueryOperatorLike, KGFieldQueryOperatorNotEqual, KGFieldQueryOperatorSimilar, KGRelationshipDirectionIncoming, KGRelationshipDirectionOutgoing } from '../models/kg.mjs';
|
|
3
|
+
import '@elqnt/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Knowledge Graph Query Builder
|
|
7
|
+
*
|
|
8
|
+
* Fluent API for building KGQuery objects programmatically.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { KGQueryBuilder, createNodeQuery } from "@elqnt/kg/utils";
|
|
13
|
+
*
|
|
14
|
+
* // Using the builder
|
|
15
|
+
* const query = new KGQueryBuilder()
|
|
16
|
+
* .label("Person")
|
|
17
|
+
* .field("age", "gt", 21)
|
|
18
|
+
* .field("status", "eq", "active")
|
|
19
|
+
* .edge("WORKS_AT", "outgoing", "Company")
|
|
20
|
+
* .limit(50)
|
|
21
|
+
* .sortBy("name", "asc")
|
|
22
|
+
* .build();
|
|
23
|
+
*
|
|
24
|
+
* // Using helper functions
|
|
25
|
+
* const simpleQuery = createNodeQuery("Product", { category: "electronics" });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Fluent builder for KGQuery objects
|
|
33
|
+
*
|
|
34
|
+
* Provides a chainable API for constructing knowledge graph queries.
|
|
35
|
+
* All methods return `this` to allow chaining.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const query = new KGQueryBuilder()
|
|
40
|
+
* .label("Person")
|
|
41
|
+
* .field("age", "gt", 21)
|
|
42
|
+
* .field("department", "eq", "Engineering")
|
|
43
|
+
* .edge("REPORTS_TO", "outgoing", "Person")
|
|
44
|
+
* .limit(100)
|
|
45
|
+
* .offset(0)
|
|
46
|
+
* .sortBy("name", "asc")
|
|
47
|
+
* .summaryOnly()
|
|
48
|
+
* .build();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare class KGQueryBuilder {
|
|
52
|
+
private _label;
|
|
53
|
+
private _fields;
|
|
54
|
+
private _edges;
|
|
55
|
+
private _limit;
|
|
56
|
+
private _depth;
|
|
57
|
+
private _offset;
|
|
58
|
+
private _sortBy;
|
|
59
|
+
private _sortOrder;
|
|
60
|
+
private _embeddingsSource?;
|
|
61
|
+
private _skipEmbedding;
|
|
62
|
+
private _summaryOnly;
|
|
63
|
+
/**
|
|
64
|
+
* Set the node label to query
|
|
65
|
+
*
|
|
66
|
+
* @param label - The node label (e.g., "Person", "Product")
|
|
67
|
+
*/
|
|
68
|
+
label(label: string): this;
|
|
69
|
+
/**
|
|
70
|
+
* Add a field filter to the query
|
|
71
|
+
*
|
|
72
|
+
* @param name - Field name
|
|
73
|
+
* @param operator - Comparison operator (eq, neq, gt, lt, gte, lte, like, similar, in, arrayContains)
|
|
74
|
+
* @param value - Value to compare against
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* builder.field("age", "gt", 21);
|
|
79
|
+
* builder.field("status", "in", ["active", "pending"]);
|
|
80
|
+
* builder.field("name", "like", "John%");
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
field(name: string, operator: KGFieldQueryOperator, value: unknown): this;
|
|
84
|
+
/**
|
|
85
|
+
* Add an equality field filter (shorthand for field(name, "eq", value))
|
|
86
|
+
*
|
|
87
|
+
* @param name - Field name
|
|
88
|
+
* @param value - Value to match
|
|
89
|
+
*/
|
|
90
|
+
where(name: string, value: unknown): this;
|
|
91
|
+
/**
|
|
92
|
+
* Add multiple equality filters at once
|
|
93
|
+
*
|
|
94
|
+
* @param fields - Object with field names as keys and values to match
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* builder.whereAll({ status: "active", type: "premium" });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
whereAll(fields: Record<string, unknown>): this;
|
|
102
|
+
/**
|
|
103
|
+
* Add an edge traversal to the query
|
|
104
|
+
*
|
|
105
|
+
* @param label - Edge label (e.g., "WORKS_AT", "REPORTS_TO")
|
|
106
|
+
* @param direction - Traversal direction ("incoming" or "outgoing")
|
|
107
|
+
* @param toLabel - Target node label (optional)
|
|
108
|
+
* @param options - Additional edge query options
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* builder.edge("WORKS_AT", "outgoing", "Company");
|
|
113
|
+
* builder.edge("REPORTS_TO", "incoming", "Person", {
|
|
114
|
+
* toFieldKey: "id",
|
|
115
|
+
* toFieldValue: "manager-123"
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
edge(label: string, direction: "incoming" | "outgoing", toLabel?: string, options?: {
|
|
120
|
+
toFieldKey?: string;
|
|
121
|
+
toFieldValue?: unknown;
|
|
122
|
+
fields?: Record<string, unknown>;
|
|
123
|
+
}): this;
|
|
124
|
+
/**
|
|
125
|
+
* Add an outgoing edge traversal
|
|
126
|
+
*
|
|
127
|
+
* @param label - Edge label
|
|
128
|
+
* @param toLabel - Target node label
|
|
129
|
+
*/
|
|
130
|
+
outgoing(label: string, toLabel?: string): this;
|
|
131
|
+
/**
|
|
132
|
+
* Add an incoming edge traversal
|
|
133
|
+
*
|
|
134
|
+
* @param label - Edge label
|
|
135
|
+
* @param toLabel - Source node label
|
|
136
|
+
*/
|
|
137
|
+
incoming(label: string, toLabel?: string): this;
|
|
138
|
+
/**
|
|
139
|
+
* Set the maximum number of results
|
|
140
|
+
*
|
|
141
|
+
* @param n - Maximum number of results (default: 100)
|
|
142
|
+
*/
|
|
143
|
+
limit(n: number): this;
|
|
144
|
+
/**
|
|
145
|
+
* Set the traversal depth
|
|
146
|
+
*
|
|
147
|
+
* @param n - Depth of edge traversal (default: 1)
|
|
148
|
+
*/
|
|
149
|
+
depth(n: number): this;
|
|
150
|
+
/**
|
|
151
|
+
* Set the result offset for pagination
|
|
152
|
+
*
|
|
153
|
+
* @param n - Number of results to skip
|
|
154
|
+
*/
|
|
155
|
+
offset(n: number): this;
|
|
156
|
+
/**
|
|
157
|
+
* Set the sort field and order
|
|
158
|
+
*
|
|
159
|
+
* @param field - Field name to sort by
|
|
160
|
+
* @param order - Sort order ("asc" or "desc")
|
|
161
|
+
*/
|
|
162
|
+
sortBy(field: string, order?: "asc" | "desc"): this;
|
|
163
|
+
/**
|
|
164
|
+
* Set the embeddings source for similarity search
|
|
165
|
+
*
|
|
166
|
+
* @param source - Embeddings source identifier
|
|
167
|
+
*/
|
|
168
|
+
embeddingsSource(source: string): this;
|
|
169
|
+
/**
|
|
170
|
+
* Skip embedding generation for this query
|
|
171
|
+
*/
|
|
172
|
+
skipEmbedding(): this;
|
|
173
|
+
/**
|
|
174
|
+
* Return only summary fields (excludes heavy fields like text, embeddings)
|
|
175
|
+
*/
|
|
176
|
+
summaryOnly(): this;
|
|
177
|
+
/**
|
|
178
|
+
* Build the final KGQuery object
|
|
179
|
+
*
|
|
180
|
+
* @returns The constructed KGQuery
|
|
181
|
+
* @throws Error if no label is set
|
|
182
|
+
*/
|
|
183
|
+
build(): KGQuery;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a simple node query with equality filters
|
|
187
|
+
*
|
|
188
|
+
* @param label - Node label to query
|
|
189
|
+
* @param fields - Optional field equality filters
|
|
190
|
+
* @param options - Additional query options
|
|
191
|
+
* @returns KGQuery object
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* // Query all Person nodes
|
|
196
|
+
* const allPeople = createNodeQuery("Person");
|
|
197
|
+
*
|
|
198
|
+
* // Query with filters
|
|
199
|
+
* const activeUsers = createNodeQuery("User", { status: "active", role: "admin" });
|
|
200
|
+
*
|
|
201
|
+
* // With options
|
|
202
|
+
* const recentProducts = createNodeQuery(
|
|
203
|
+
* "Product",
|
|
204
|
+
* { inStock: true },
|
|
205
|
+
* { limit: 10, sortBy: "createdAt", sortOrder: "desc" }
|
|
206
|
+
* );
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
declare function createNodeQuery(label: string, fields?: Record<string, unknown>, options?: {
|
|
210
|
+
limit?: number;
|
|
211
|
+
depth?: number;
|
|
212
|
+
sortBy?: string;
|
|
213
|
+
sortOrder?: "asc" | "desc";
|
|
214
|
+
summaryOnly?: boolean;
|
|
215
|
+
}): KGQuery;
|
|
216
|
+
/**
|
|
217
|
+
* Create an edge query object
|
|
218
|
+
*
|
|
219
|
+
* @param label - Edge label
|
|
220
|
+
* @param direction - Traversal direction
|
|
221
|
+
* @param options - Additional edge options
|
|
222
|
+
* @returns KGEdgeQuery object
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const worksAtEdge = createEdgeQuery("WORKS_AT", "outgoing", {
|
|
227
|
+
* toLabel: "Company",
|
|
228
|
+
* toFieldKey: "name",
|
|
229
|
+
* toFieldValue: "Acme Corp"
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
declare function createEdgeQuery(label: string, direction?: "incoming" | "outgoing", options?: {
|
|
234
|
+
toLabel?: string;
|
|
235
|
+
toFieldKey?: string;
|
|
236
|
+
toFieldValue?: unknown;
|
|
237
|
+
fields?: Record<string, unknown>;
|
|
238
|
+
}): KGEdgeQuery;
|
|
239
|
+
/**
|
|
240
|
+
* Create a field query object
|
|
241
|
+
*
|
|
242
|
+
* @param name - Field name
|
|
243
|
+
* @param operator - Comparison operator
|
|
244
|
+
* @param value - Value to compare against
|
|
245
|
+
* @returns KGFieldQuery object
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* const ageFilter = createFieldQuery("age", "gt", 21);
|
|
250
|
+
* const statusFilter = createFieldQuery("status", "in", ["active", "pending"]);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
declare function createFieldQuery(name: string, operator: KGFieldQueryOperator, value: unknown): KGFieldQuery;
|
|
254
|
+
/**
|
|
255
|
+
* Create a similarity search query
|
|
256
|
+
*
|
|
257
|
+
* @param label - Node label to search
|
|
258
|
+
* @param searchText - Text to find similar nodes for
|
|
259
|
+
* @param options - Additional query options
|
|
260
|
+
* @returns KGQuery object configured for similarity search
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* const similarDocs = createSimilarityQuery(
|
|
265
|
+
* "Document",
|
|
266
|
+
* "machine learning algorithms",
|
|
267
|
+
* { limit: 10, embeddingsSource: "openai" }
|
|
268
|
+
* );
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
declare function createSimilarityQuery(label: string, searchText: string, options?: {
|
|
272
|
+
embeddingsSource?: string;
|
|
273
|
+
limit?: number;
|
|
274
|
+
summaryOnly?: boolean;
|
|
275
|
+
}): KGQuery;
|
|
276
|
+
|
|
277
|
+
export { KGQueryBuilder, createEdgeQuery, createFieldQuery, createNodeQuery, createSimilarityQuery };
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { KGFieldQueryOperator, KGQuery, KGEdgeQuery, KGFieldQuery } from '../models/kg.js';
|
|
2
|
+
export { KGFieldQueryOperatorArrayContains, KGFieldQueryOperatorEqual, KGFieldQueryOperatorGreater, KGFieldQueryOperatorGreaterOrEqual, KGFieldQueryOperatorIn, KGFieldQueryOperatorLess, KGFieldQueryOperatorLessOrEqual, KGFieldQueryOperatorLike, KGFieldQueryOperatorNotEqual, KGFieldQueryOperatorSimilar, KGRelationshipDirectionIncoming, KGRelationshipDirectionOutgoing } from '../models/kg.js';
|
|
3
|
+
import '@elqnt/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Knowledge Graph Query Builder
|
|
7
|
+
*
|
|
8
|
+
* Fluent API for building KGQuery objects programmatically.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { KGQueryBuilder, createNodeQuery } from "@elqnt/kg/utils";
|
|
13
|
+
*
|
|
14
|
+
* // Using the builder
|
|
15
|
+
* const query = new KGQueryBuilder()
|
|
16
|
+
* .label("Person")
|
|
17
|
+
* .field("age", "gt", 21)
|
|
18
|
+
* .field("status", "eq", "active")
|
|
19
|
+
* .edge("WORKS_AT", "outgoing", "Company")
|
|
20
|
+
* .limit(50)
|
|
21
|
+
* .sortBy("name", "asc")
|
|
22
|
+
* .build();
|
|
23
|
+
*
|
|
24
|
+
* // Using helper functions
|
|
25
|
+
* const simpleQuery = createNodeQuery("Product", { category: "electronics" });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Fluent builder for KGQuery objects
|
|
33
|
+
*
|
|
34
|
+
* Provides a chainable API for constructing knowledge graph queries.
|
|
35
|
+
* All methods return `this` to allow chaining.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const query = new KGQueryBuilder()
|
|
40
|
+
* .label("Person")
|
|
41
|
+
* .field("age", "gt", 21)
|
|
42
|
+
* .field("department", "eq", "Engineering")
|
|
43
|
+
* .edge("REPORTS_TO", "outgoing", "Person")
|
|
44
|
+
* .limit(100)
|
|
45
|
+
* .offset(0)
|
|
46
|
+
* .sortBy("name", "asc")
|
|
47
|
+
* .summaryOnly()
|
|
48
|
+
* .build();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare class KGQueryBuilder {
|
|
52
|
+
private _label;
|
|
53
|
+
private _fields;
|
|
54
|
+
private _edges;
|
|
55
|
+
private _limit;
|
|
56
|
+
private _depth;
|
|
57
|
+
private _offset;
|
|
58
|
+
private _sortBy;
|
|
59
|
+
private _sortOrder;
|
|
60
|
+
private _embeddingsSource?;
|
|
61
|
+
private _skipEmbedding;
|
|
62
|
+
private _summaryOnly;
|
|
63
|
+
/**
|
|
64
|
+
* Set the node label to query
|
|
65
|
+
*
|
|
66
|
+
* @param label - The node label (e.g., "Person", "Product")
|
|
67
|
+
*/
|
|
68
|
+
label(label: string): this;
|
|
69
|
+
/**
|
|
70
|
+
* Add a field filter to the query
|
|
71
|
+
*
|
|
72
|
+
* @param name - Field name
|
|
73
|
+
* @param operator - Comparison operator (eq, neq, gt, lt, gte, lte, like, similar, in, arrayContains)
|
|
74
|
+
* @param value - Value to compare against
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* builder.field("age", "gt", 21);
|
|
79
|
+
* builder.field("status", "in", ["active", "pending"]);
|
|
80
|
+
* builder.field("name", "like", "John%");
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
field(name: string, operator: KGFieldQueryOperator, value: unknown): this;
|
|
84
|
+
/**
|
|
85
|
+
* Add an equality field filter (shorthand for field(name, "eq", value))
|
|
86
|
+
*
|
|
87
|
+
* @param name - Field name
|
|
88
|
+
* @param value - Value to match
|
|
89
|
+
*/
|
|
90
|
+
where(name: string, value: unknown): this;
|
|
91
|
+
/**
|
|
92
|
+
* Add multiple equality filters at once
|
|
93
|
+
*
|
|
94
|
+
* @param fields - Object with field names as keys and values to match
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* builder.whereAll({ status: "active", type: "premium" });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
whereAll(fields: Record<string, unknown>): this;
|
|
102
|
+
/**
|
|
103
|
+
* Add an edge traversal to the query
|
|
104
|
+
*
|
|
105
|
+
* @param label - Edge label (e.g., "WORKS_AT", "REPORTS_TO")
|
|
106
|
+
* @param direction - Traversal direction ("incoming" or "outgoing")
|
|
107
|
+
* @param toLabel - Target node label (optional)
|
|
108
|
+
* @param options - Additional edge query options
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* builder.edge("WORKS_AT", "outgoing", "Company");
|
|
113
|
+
* builder.edge("REPORTS_TO", "incoming", "Person", {
|
|
114
|
+
* toFieldKey: "id",
|
|
115
|
+
* toFieldValue: "manager-123"
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
edge(label: string, direction: "incoming" | "outgoing", toLabel?: string, options?: {
|
|
120
|
+
toFieldKey?: string;
|
|
121
|
+
toFieldValue?: unknown;
|
|
122
|
+
fields?: Record<string, unknown>;
|
|
123
|
+
}): this;
|
|
124
|
+
/**
|
|
125
|
+
* Add an outgoing edge traversal
|
|
126
|
+
*
|
|
127
|
+
* @param label - Edge label
|
|
128
|
+
* @param toLabel - Target node label
|
|
129
|
+
*/
|
|
130
|
+
outgoing(label: string, toLabel?: string): this;
|
|
131
|
+
/**
|
|
132
|
+
* Add an incoming edge traversal
|
|
133
|
+
*
|
|
134
|
+
* @param label - Edge label
|
|
135
|
+
* @param toLabel - Source node label
|
|
136
|
+
*/
|
|
137
|
+
incoming(label: string, toLabel?: string): this;
|
|
138
|
+
/**
|
|
139
|
+
* Set the maximum number of results
|
|
140
|
+
*
|
|
141
|
+
* @param n - Maximum number of results (default: 100)
|
|
142
|
+
*/
|
|
143
|
+
limit(n: number): this;
|
|
144
|
+
/**
|
|
145
|
+
* Set the traversal depth
|
|
146
|
+
*
|
|
147
|
+
* @param n - Depth of edge traversal (default: 1)
|
|
148
|
+
*/
|
|
149
|
+
depth(n: number): this;
|
|
150
|
+
/**
|
|
151
|
+
* Set the result offset for pagination
|
|
152
|
+
*
|
|
153
|
+
* @param n - Number of results to skip
|
|
154
|
+
*/
|
|
155
|
+
offset(n: number): this;
|
|
156
|
+
/**
|
|
157
|
+
* Set the sort field and order
|
|
158
|
+
*
|
|
159
|
+
* @param field - Field name to sort by
|
|
160
|
+
* @param order - Sort order ("asc" or "desc")
|
|
161
|
+
*/
|
|
162
|
+
sortBy(field: string, order?: "asc" | "desc"): this;
|
|
163
|
+
/**
|
|
164
|
+
* Set the embeddings source for similarity search
|
|
165
|
+
*
|
|
166
|
+
* @param source - Embeddings source identifier
|
|
167
|
+
*/
|
|
168
|
+
embeddingsSource(source: string): this;
|
|
169
|
+
/**
|
|
170
|
+
* Skip embedding generation for this query
|
|
171
|
+
*/
|
|
172
|
+
skipEmbedding(): this;
|
|
173
|
+
/**
|
|
174
|
+
* Return only summary fields (excludes heavy fields like text, embeddings)
|
|
175
|
+
*/
|
|
176
|
+
summaryOnly(): this;
|
|
177
|
+
/**
|
|
178
|
+
* Build the final KGQuery object
|
|
179
|
+
*
|
|
180
|
+
* @returns The constructed KGQuery
|
|
181
|
+
* @throws Error if no label is set
|
|
182
|
+
*/
|
|
183
|
+
build(): KGQuery;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a simple node query with equality filters
|
|
187
|
+
*
|
|
188
|
+
* @param label - Node label to query
|
|
189
|
+
* @param fields - Optional field equality filters
|
|
190
|
+
* @param options - Additional query options
|
|
191
|
+
* @returns KGQuery object
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* // Query all Person nodes
|
|
196
|
+
* const allPeople = createNodeQuery("Person");
|
|
197
|
+
*
|
|
198
|
+
* // Query with filters
|
|
199
|
+
* const activeUsers = createNodeQuery("User", { status: "active", role: "admin" });
|
|
200
|
+
*
|
|
201
|
+
* // With options
|
|
202
|
+
* const recentProducts = createNodeQuery(
|
|
203
|
+
* "Product",
|
|
204
|
+
* { inStock: true },
|
|
205
|
+
* { limit: 10, sortBy: "createdAt", sortOrder: "desc" }
|
|
206
|
+
* );
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
declare function createNodeQuery(label: string, fields?: Record<string, unknown>, options?: {
|
|
210
|
+
limit?: number;
|
|
211
|
+
depth?: number;
|
|
212
|
+
sortBy?: string;
|
|
213
|
+
sortOrder?: "asc" | "desc";
|
|
214
|
+
summaryOnly?: boolean;
|
|
215
|
+
}): KGQuery;
|
|
216
|
+
/**
|
|
217
|
+
* Create an edge query object
|
|
218
|
+
*
|
|
219
|
+
* @param label - Edge label
|
|
220
|
+
* @param direction - Traversal direction
|
|
221
|
+
* @param options - Additional edge options
|
|
222
|
+
* @returns KGEdgeQuery object
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const worksAtEdge = createEdgeQuery("WORKS_AT", "outgoing", {
|
|
227
|
+
* toLabel: "Company",
|
|
228
|
+
* toFieldKey: "name",
|
|
229
|
+
* toFieldValue: "Acme Corp"
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
declare function createEdgeQuery(label: string, direction?: "incoming" | "outgoing", options?: {
|
|
234
|
+
toLabel?: string;
|
|
235
|
+
toFieldKey?: string;
|
|
236
|
+
toFieldValue?: unknown;
|
|
237
|
+
fields?: Record<string, unknown>;
|
|
238
|
+
}): KGEdgeQuery;
|
|
239
|
+
/**
|
|
240
|
+
* Create a field query object
|
|
241
|
+
*
|
|
242
|
+
* @param name - Field name
|
|
243
|
+
* @param operator - Comparison operator
|
|
244
|
+
* @param value - Value to compare against
|
|
245
|
+
* @returns KGFieldQuery object
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* const ageFilter = createFieldQuery("age", "gt", 21);
|
|
250
|
+
* const statusFilter = createFieldQuery("status", "in", ["active", "pending"]);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
declare function createFieldQuery(name: string, operator: KGFieldQueryOperator, value: unknown): KGFieldQuery;
|
|
254
|
+
/**
|
|
255
|
+
* Create a similarity search query
|
|
256
|
+
*
|
|
257
|
+
* @param label - Node label to search
|
|
258
|
+
* @param searchText - Text to find similar nodes for
|
|
259
|
+
* @param options - Additional query options
|
|
260
|
+
* @returns KGQuery object configured for similarity search
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* const similarDocs = createSimilarityQuery(
|
|
265
|
+
* "Document",
|
|
266
|
+
* "machine learning algorithms",
|
|
267
|
+
* { limit: 10, embeddingsSource: "openai" }
|
|
268
|
+
* );
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
declare function createSimilarityQuery(label: string, searchText: string, options?: {
|
|
272
|
+
embeddingsSource?: string;
|
|
273
|
+
limit?: number;
|
|
274
|
+
summaryOnly?: boolean;
|
|
275
|
+
}): KGQuery;
|
|
276
|
+
|
|
277
|
+
export { KGQueryBuilder, createEdgeQuery, createFieldQuery, createNodeQuery, createSimilarityQuery };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkADIKUMMIjs = require('../chunk-ADIKUMMI.js');
|
|
9
|
+
require('../chunk-W4XVBGE7.js');
|
|
10
|
+
require('../chunk-67SUELDR.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var _chunkUCKE66GBjs = require('../chunk-UCKE66GB.js');
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
exports.KGFieldQueryOperatorArrayContains = _chunkUCKE66GBjs.KGFieldQueryOperatorArrayContains; exports.KGFieldQueryOperatorEqual = _chunkUCKE66GBjs.KGFieldQueryOperatorEqual; exports.KGFieldQueryOperatorGreater = _chunkUCKE66GBjs.KGFieldQueryOperatorGreater; exports.KGFieldQueryOperatorGreaterOrEqual = _chunkUCKE66GBjs.KGFieldQueryOperatorGreaterOrEqual; exports.KGFieldQueryOperatorIn = _chunkUCKE66GBjs.KGFieldQueryOperatorIn; exports.KGFieldQueryOperatorLess = _chunkUCKE66GBjs.KGFieldQueryOperatorLess; exports.KGFieldQueryOperatorLessOrEqual = _chunkUCKE66GBjs.KGFieldQueryOperatorLessOrEqual; exports.KGFieldQueryOperatorLike = _chunkUCKE66GBjs.KGFieldQueryOperatorLike; exports.KGFieldQueryOperatorNotEqual = _chunkUCKE66GBjs.KGFieldQueryOperatorNotEqual; exports.KGFieldQueryOperatorSimilar = _chunkUCKE66GBjs.KGFieldQueryOperatorSimilar; exports.KGQueryBuilder = _chunkADIKUMMIjs.KGQueryBuilder; exports.KGRelationshipDirectionIncoming = _chunkUCKE66GBjs.KGRelationshipDirectionIncoming; exports.KGRelationshipDirectionOutgoing = _chunkUCKE66GBjs.KGRelationshipDirectionOutgoing; exports.createEdgeQuery = _chunkADIKUMMIjs.createEdgeQuery; exports.createFieldQuery = _chunkADIKUMMIjs.createFieldQuery; exports.createNodeQuery = _chunkADIKUMMIjs.createNodeQuery; exports.createSimilarityQuery = _chunkADIKUMMIjs.createSimilarityQuery;
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/eloquent/eloquent/packages/@elqnt/kg/dist/utils/index.js"],"names":[],"mappings":"AAAA,qFAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,i0CAAC","file":"/home/runner/work/eloquent/eloquent/packages/@elqnt/kg/dist/utils/index.js"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
KGQueryBuilder,
|
|
4
|
+
createEdgeQuery,
|
|
5
|
+
createFieldQuery,
|
|
6
|
+
createNodeQuery,
|
|
7
|
+
createSimilarityQuery
|
|
8
|
+
} from "../chunk-CAXPQTKI.mjs";
|
|
9
|
+
import "../chunk-NJNBEGDB.mjs";
|
|
10
|
+
import "../chunk-RDIQ7HTM.mjs";
|
|
11
|
+
import {
|
|
12
|
+
KGFieldQueryOperatorArrayContains,
|
|
13
|
+
KGFieldQueryOperatorEqual,
|
|
14
|
+
KGFieldQueryOperatorGreater,
|
|
15
|
+
KGFieldQueryOperatorGreaterOrEqual,
|
|
16
|
+
KGFieldQueryOperatorIn,
|
|
17
|
+
KGFieldQueryOperatorLess,
|
|
18
|
+
KGFieldQueryOperatorLessOrEqual,
|
|
19
|
+
KGFieldQueryOperatorLike,
|
|
20
|
+
KGFieldQueryOperatorNotEqual,
|
|
21
|
+
KGFieldQueryOperatorSimilar,
|
|
22
|
+
KGRelationshipDirectionIncoming,
|
|
23
|
+
KGRelationshipDirectionOutgoing
|
|
24
|
+
} from "../chunk-VUSVP6OI.mjs";
|
|
25
|
+
export {
|
|
26
|
+
KGFieldQueryOperatorArrayContains,
|
|
27
|
+
KGFieldQueryOperatorEqual,
|
|
28
|
+
KGFieldQueryOperatorGreater,
|
|
29
|
+
KGFieldQueryOperatorGreaterOrEqual,
|
|
30
|
+
KGFieldQueryOperatorIn,
|
|
31
|
+
KGFieldQueryOperatorLess,
|
|
32
|
+
KGFieldQueryOperatorLessOrEqual,
|
|
33
|
+
KGFieldQueryOperatorLike,
|
|
34
|
+
KGFieldQueryOperatorNotEqual,
|
|
35
|
+
KGFieldQueryOperatorSimilar,
|
|
36
|
+
KGQueryBuilder,
|
|
37
|
+
KGRelationshipDirectionIncoming,
|
|
38
|
+
KGRelationshipDirectionOutgoing,
|
|
39
|
+
createEdgeQuery,
|
|
40
|
+
createFieldQuery,
|
|
41
|
+
createNodeQuery,
|
|
42
|
+
createSimilarityQuery
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elqnt/kg",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Knowledge graph
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "Knowledge graph SDK for Eloquent platform - types, browser & server APIs, React hooks, and query utilities",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,10 +31,20 @@
|
|
|
31
31
|
"import": "./dist/api/index.mjs",
|
|
32
32
|
"require": "./dist/api/index.js"
|
|
33
33
|
},
|
|
34
|
+
"./api/server": {
|
|
35
|
+
"types": "./dist/api/server.d.ts",
|
|
36
|
+
"import": "./dist/api/server.mjs",
|
|
37
|
+
"require": "./dist/api/server.js"
|
|
38
|
+
},
|
|
34
39
|
"./hooks": {
|
|
35
40
|
"types": "./dist/hooks/index.d.ts",
|
|
36
41
|
"import": "./dist/hooks/index.mjs",
|
|
37
42
|
"require": "./dist/hooks/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./utils": {
|
|
45
|
+
"types": "./dist/utils/index.d.ts",
|
|
46
|
+
"import": "./dist/utils/index.mjs",
|
|
47
|
+
"require": "./dist/utils/index.js"
|
|
38
48
|
}
|
|
39
49
|
},
|
|
40
50
|
"files": [
|
|
@@ -46,8 +56,8 @@
|
|
|
46
56
|
"directory": "packages/kg"
|
|
47
57
|
},
|
|
48
58
|
"dependencies": {
|
|
49
|
-
"@elqnt/types": "2.0.
|
|
50
|
-
"@elqnt/api-client": "1.0.
|
|
59
|
+
"@elqnt/types": "2.0.13",
|
|
60
|
+
"@elqnt/api-client": "1.0.4"
|
|
51
61
|
},
|
|
52
62
|
"peerDependencies": {
|
|
53
63
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -57,7 +67,7 @@
|
|
|
57
67
|
"react": "^19.0.0",
|
|
58
68
|
"tsup": "^8.0.0",
|
|
59
69
|
"typescript": "^5.0.0",
|
|
60
|
-
"@elqnt/api-client": "1.0.
|
|
70
|
+
"@elqnt/api-client": "1.0.4"
|
|
61
71
|
},
|
|
62
72
|
"scripts": {
|
|
63
73
|
"build": "tsup",
|