@wiscale/velesdb-sdk 1.15.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +356 -20
- package/README.md +115 -14
- package/dist/index.d.mts +91 -28
- package/dist/index.d.ts +91 -28
- package/dist/index.js +188 -116
- package/dist/index.mjs +187 -116
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -105,6 +105,7 @@ __export(index_exports, {
|
|
|
105
105
|
IoError: () => IoError,
|
|
106
106
|
NodeNotFoundError: () => NodeNotFoundError,
|
|
107
107
|
NotFoundError: () => NotFoundError,
|
|
108
|
+
OpenAIEmbedder: () => OpenAIEmbedder,
|
|
108
109
|
OverflowError: () => OverflowError,
|
|
109
110
|
PointNotFoundError: () => PointNotFoundError,
|
|
110
111
|
QueryError: () => QueryError,
|
|
@@ -725,49 +726,49 @@ var VELES_ERROR_CODES = [
|
|
|
725
726
|
"VELES-035",
|
|
726
727
|
"VELES-036"
|
|
727
728
|
];
|
|
728
|
-
var CODE_TO_CLASS =
|
|
729
|
-
"VELES-001"
|
|
730
|
-
"VELES-002"
|
|
731
|
-
"VELES-003"
|
|
732
|
-
"VELES-004"
|
|
733
|
-
"VELES-005"
|
|
734
|
-
"VELES-006"
|
|
735
|
-
"VELES-007"
|
|
736
|
-
"VELES-008"
|
|
737
|
-
"VELES-009"
|
|
738
|
-
"VELES-010"
|
|
739
|
-
"VELES-011"
|
|
740
|
-
"VELES-012"
|
|
741
|
-
"VELES-013"
|
|
742
|
-
"VELES-014"
|
|
743
|
-
"VELES-015"
|
|
744
|
-
"VELES-016"
|
|
745
|
-
"VELES-017"
|
|
746
|
-
"VELES-018"
|
|
747
|
-
"VELES-019"
|
|
748
|
-
"VELES-020"
|
|
749
|
-
"VELES-021"
|
|
750
|
-
"VELES-022"
|
|
751
|
-
"VELES-023"
|
|
752
|
-
"VELES-024"
|
|
753
|
-
"VELES-025"
|
|
754
|
-
"VELES-026"
|
|
755
|
-
"VELES-027"
|
|
756
|
-
"VELES-028"
|
|
757
|
-
"VELES-029"
|
|
758
|
-
"VELES-030"
|
|
759
|
-
"VELES-031"
|
|
760
|
-
"VELES-032"
|
|
761
|
-
"VELES-033"
|
|
762
|
-
"VELES-034"
|
|
763
|
-
"VELES-035"
|
|
764
|
-
"VELES-036"
|
|
765
|
-
|
|
729
|
+
var CODE_TO_CLASS = /* @__PURE__ */ new Map([
|
|
730
|
+
["VELES-001", CollectionExistsError],
|
|
731
|
+
["VELES-002", CollectionNotFoundError],
|
|
732
|
+
["VELES-003", PointNotFoundError],
|
|
733
|
+
["VELES-004", DimensionMismatchError],
|
|
734
|
+
["VELES-005", InvalidVectorError],
|
|
735
|
+
["VELES-006", StorageError],
|
|
736
|
+
["VELES-007", IndexError],
|
|
737
|
+
["VELES-008", IndexCorruptedError],
|
|
738
|
+
["VELES-009", ConfigError],
|
|
739
|
+
["VELES-010", QueryError],
|
|
740
|
+
["VELES-011", IoError],
|
|
741
|
+
["VELES-012", SerializationError],
|
|
742
|
+
["VELES-013", InternalError],
|
|
743
|
+
["VELES-014", VectorNotAllowedError],
|
|
744
|
+
["VELES-015", SearchNotSupportedError],
|
|
745
|
+
["VELES-016", VectorRequiredError],
|
|
746
|
+
["VELES-017", SchemaValidationError],
|
|
747
|
+
["VELES-018", GraphNotSupportedError],
|
|
748
|
+
["VELES-019", EdgeExistsError],
|
|
749
|
+
["VELES-020", EdgeNotFoundError],
|
|
750
|
+
["VELES-021", InvalidEdgeLabelError],
|
|
751
|
+
["VELES-022", NodeNotFoundError],
|
|
752
|
+
["VELES-023", OverflowError],
|
|
753
|
+
["VELES-024", ColumnStoreError],
|
|
754
|
+
["VELES-025", GpuError],
|
|
755
|
+
["VELES-026", EpochMismatchError],
|
|
756
|
+
["VELES-027", GuardRailError],
|
|
757
|
+
["VELES-028", InvalidQuantizerConfigError],
|
|
758
|
+
["VELES-029", TrainingFailedError],
|
|
759
|
+
["VELES-030", SparseIndexError],
|
|
760
|
+
["VELES-031", DatabaseLockedError],
|
|
761
|
+
["VELES-032", InvalidDimensionError],
|
|
762
|
+
["VELES-033", AllocationFailedError],
|
|
763
|
+
["VELES-034", InvalidCollectionNameError],
|
|
764
|
+
["VELES-035", SnapshotBuildFailedError],
|
|
765
|
+
["VELES-036", IncompatibleSchemaVersionError]
|
|
766
|
+
]);
|
|
766
767
|
function parseVelesError(code, message) {
|
|
767
768
|
if (code === null || code === void 0) {
|
|
768
769
|
return new VelesError(message, "VELES-UNKNOWN");
|
|
769
770
|
}
|
|
770
|
-
const Cls = CODE_TO_CLASS
|
|
771
|
+
const Cls = CODE_TO_CLASS.get(code);
|
|
771
772
|
if (Cls !== void 0) {
|
|
772
773
|
return new Cls(message);
|
|
773
774
|
}
|
|
@@ -1814,16 +1815,13 @@ async function getEdgeCount(transport, collection) {
|
|
|
1814
1815
|
return response.data?.count ?? 0;
|
|
1815
1816
|
}
|
|
1816
1817
|
async function listNodes(transport, collection) {
|
|
1817
|
-
const response = await transport.requestJson(
|
|
1818
|
-
"GET",
|
|
1819
|
-
`${collectionPath(collection)}/graph/nodes`
|
|
1820
|
-
);
|
|
1818
|
+
const response = await transport.requestJson("GET", `${collectionPath(collection)}/graph/nodes`);
|
|
1821
1819
|
throwOnError(response, `Collection '${collection}'`);
|
|
1822
1820
|
const data = response.data;
|
|
1823
1821
|
return { nodeIds: data.node_ids, count: data.count };
|
|
1824
1822
|
}
|
|
1825
|
-
function
|
|
1826
|
-
return
|
|
1823
|
+
function idToGraphId(id) {
|
|
1824
|
+
return id;
|
|
1827
1825
|
}
|
|
1828
1826
|
async function getNodeEdges(transport, collection, nodeId, options) {
|
|
1829
1827
|
const params = new URLSearchParams();
|
|
@@ -1834,9 +1832,9 @@ async function getNodeEdges(transport, collection, nodeId, options) {
|
|
|
1834
1832
|
const response = await transport.requestJson("GET", url);
|
|
1835
1833
|
throwOnError(response, `Collection '${collection}'`);
|
|
1836
1834
|
return (response.data?.edges ?? []).map((e) => ({
|
|
1837
|
-
id:
|
|
1838
|
-
source:
|
|
1839
|
-
target:
|
|
1835
|
+
id: e.id,
|
|
1836
|
+
source: e.source,
|
|
1837
|
+
target: e.target,
|
|
1840
1838
|
label: e.label,
|
|
1841
1839
|
properties: e.properties
|
|
1842
1840
|
}));
|
|
@@ -1846,7 +1844,7 @@ async function getNodePayload(transport, collection, nodeId) {
|
|
|
1846
1844
|
throwOnError(response, `Collection '${collection}'`);
|
|
1847
1845
|
const data = response.data;
|
|
1848
1846
|
return {
|
|
1849
|
-
nodeId:
|
|
1847
|
+
nodeId: idToGraphId(data.node_id),
|
|
1850
1848
|
payload: data.payload
|
|
1851
1849
|
};
|
|
1852
1850
|
}
|
|
@@ -1870,7 +1868,7 @@ async function graphSearch(transport, collection, request2) {
|
|
|
1870
1868
|
throwOnError(response, `Collection '${collection}'`);
|
|
1871
1869
|
const items = (response.data?.results ?? []).map(
|
|
1872
1870
|
(r) => ({
|
|
1873
|
-
id:
|
|
1871
|
+
id: idToGraphId(r.id),
|
|
1874
1872
|
score: r.score,
|
|
1875
1873
|
payload: r.payload
|
|
1876
1874
|
})
|
|
@@ -1904,9 +1902,11 @@ async function storeSemanticFact(transport, collection, entry) {
|
|
|
1904
1902
|
id: entry.id,
|
|
1905
1903
|
vector: entry.embedding,
|
|
1906
1904
|
payload: {
|
|
1905
|
+
// Caller metadata is spread first so the reserved keys below
|
|
1906
|
+
// (`_memory_type`, `text`) always win and cannot be clobbered.
|
|
1907
|
+
...entry.metadata,
|
|
1907
1908
|
_memory_type: "semantic",
|
|
1908
|
-
text: entry.text
|
|
1909
|
-
...entry.metadata
|
|
1909
|
+
text: entry.text
|
|
1910
1910
|
}
|
|
1911
1911
|
}]
|
|
1912
1912
|
}
|
|
@@ -1926,16 +1926,20 @@ async function recordEpisodicEvent(transport, collection, event) {
|
|
|
1926
1926
|
id,
|
|
1927
1927
|
vector: event.embedding,
|
|
1928
1928
|
payload: {
|
|
1929
|
+
// Caller-supplied data/metadata is spread first so the reserved
|
|
1930
|
+
// keys below (`_memory_type`, `event_type`, `timestamp`) always
|
|
1931
|
+
// win and cannot be clobbered.
|
|
1932
|
+
...event.data,
|
|
1933
|
+
...event.metadata,
|
|
1929
1934
|
_memory_type: "episodic",
|
|
1930
1935
|
event_type: event.eventType,
|
|
1931
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1932
|
-
...event.data,
|
|
1933
|
-
...event.metadata
|
|
1936
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1934
1937
|
}
|
|
1935
1938
|
}]
|
|
1936
1939
|
}
|
|
1937
1940
|
);
|
|
1938
1941
|
throwOnError(response);
|
|
1942
|
+
return id;
|
|
1939
1943
|
}
|
|
1940
1944
|
async function recallEpisodicEvents(transport, collection, embedding, k = 5) {
|
|
1941
1945
|
return transport.searchVectors(collection, embedding, k, { _memory_type: "episodic" });
|
|
@@ -1948,16 +1952,21 @@ async function storeProceduralPattern(transport, collection, pattern) {
|
|
|
1948
1952
|
{
|
|
1949
1953
|
points: [{
|
|
1950
1954
|
id,
|
|
1955
|
+
vector: pattern.embedding,
|
|
1951
1956
|
payload: {
|
|
1957
|
+
// Caller metadata is spread first so the reserved keys below
|
|
1958
|
+
// (`_memory_type`, `name`, `steps`) always win and cannot be
|
|
1959
|
+
// clobbered.
|
|
1960
|
+
...pattern.metadata,
|
|
1952
1961
|
_memory_type: "procedural",
|
|
1953
1962
|
name: pattern.name,
|
|
1954
|
-
steps: pattern.steps
|
|
1955
|
-
...pattern.metadata
|
|
1963
|
+
steps: pattern.steps
|
|
1956
1964
|
}
|
|
1957
1965
|
}]
|
|
1958
1966
|
}
|
|
1959
1967
|
);
|
|
1960
1968
|
throwOnError(response);
|
|
1969
|
+
return id;
|
|
1961
1970
|
}
|
|
1962
1971
|
async function matchProceduralPatterns(transport, collection, embedding, k = 5) {
|
|
1963
1972
|
return transport.searchVectors(collection, embedding, k, { _memory_type: "procedural" });
|
|
@@ -2111,15 +2120,29 @@ async function addEdge(transport, collection, edge) {
|
|
|
2111
2120
|
throwOnError(response, `Collection '${collection}'`);
|
|
2112
2121
|
}
|
|
2113
2122
|
function toGraphEdge(e) {
|
|
2114
|
-
const toNum = (v) => typeof v === "string" ? Number(v) : v;
|
|
2115
2123
|
return {
|
|
2116
|
-
id:
|
|
2117
|
-
source:
|
|
2118
|
-
target:
|
|
2124
|
+
id: e.id,
|
|
2125
|
+
source: e.source,
|
|
2126
|
+
target: e.target,
|
|
2119
2127
|
label: e.label,
|
|
2120
2128
|
properties: e.properties
|
|
2121
2129
|
};
|
|
2122
2130
|
}
|
|
2131
|
+
function toTraverseResponse(data) {
|
|
2132
|
+
return {
|
|
2133
|
+
results: data.results.map((r) => ({
|
|
2134
|
+
targetId: r.target_id,
|
|
2135
|
+
depth: r.depth,
|
|
2136
|
+
path: r.path
|
|
2137
|
+
})),
|
|
2138
|
+
nextCursor: data.next_cursor ?? void 0,
|
|
2139
|
+
hasMore: data.has_more,
|
|
2140
|
+
stats: {
|
|
2141
|
+
visited: data.stats.visited,
|
|
2142
|
+
depthReached: data.stats.depth_reached
|
|
2143
|
+
}
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2123
2146
|
async function getEdges(transport, collection, options) {
|
|
2124
2147
|
const queryParams = options?.label ? `?label=${encodeURIComponent(options.label)}` : "";
|
|
2125
2148
|
const response = await transport.requestJson(
|
|
@@ -2143,20 +2166,7 @@ async function traverseGraph(transport, collection, request2) {
|
|
|
2143
2166
|
}
|
|
2144
2167
|
);
|
|
2145
2168
|
throwOnError(response, `Collection '${collection}'`);
|
|
2146
|
-
|
|
2147
|
-
return {
|
|
2148
|
-
results: data.results.map((r) => ({
|
|
2149
|
-
targetId: r.target_id,
|
|
2150
|
-
depth: r.depth,
|
|
2151
|
-
path: r.path
|
|
2152
|
-
})),
|
|
2153
|
-
nextCursor: data.next_cursor ?? void 0,
|
|
2154
|
-
hasMore: data.has_more,
|
|
2155
|
-
stats: {
|
|
2156
|
-
visited: data.stats.visited,
|
|
2157
|
-
depthReached: data.stats.depth_reached
|
|
2158
|
-
}
|
|
2159
|
-
};
|
|
2169
|
+
return toTraverseResponse(response.data);
|
|
2160
2170
|
}
|
|
2161
2171
|
async function getNodeDegree(transport, collection, nodeId) {
|
|
2162
2172
|
const response = await transport.requestJson(
|
|
@@ -2191,20 +2201,7 @@ async function traverseParallel(transport, collection, request2) {
|
|
|
2191
2201
|
}
|
|
2192
2202
|
);
|
|
2193
2203
|
throwOnError(response, `Collection '${collection}'`);
|
|
2194
|
-
|
|
2195
|
-
return {
|
|
2196
|
-
results: data.results.map((r) => ({
|
|
2197
|
-
targetId: r.target_id,
|
|
2198
|
-
depth: r.depth,
|
|
2199
|
-
path: r.path
|
|
2200
|
-
})),
|
|
2201
|
-
nextCursor: data.next_cursor ?? void 0,
|
|
2202
|
-
hasMore: data.has_more,
|
|
2203
|
-
stats: {
|
|
2204
|
-
visited: data.stats.visited,
|
|
2205
|
-
depthReached: data.stats.depth_reached
|
|
2206
|
-
}
|
|
2207
|
-
};
|
|
2204
|
+
return toTraverseResponse(response.data);
|
|
2208
2205
|
}
|
|
2209
2206
|
|
|
2210
2207
|
// src/backends/query-backend.ts
|
|
@@ -2889,7 +2886,16 @@ var AgentMemoryClient = class {
|
|
|
2889
2886
|
this.backend = backend;
|
|
2890
2887
|
this.config = config;
|
|
2891
2888
|
}
|
|
2892
|
-
/**
|
|
2889
|
+
/**
|
|
2890
|
+
* Advisory embedding dimension passed at construction (default: 384).
|
|
2891
|
+
*
|
|
2892
|
+
* This value is **not** enforced and does not create or size any
|
|
2893
|
+
* collection — the dimension that actually governs storage and search
|
|
2894
|
+
* is the one fixed when the collection was created
|
|
2895
|
+
* (`db.createCollection(name, { dimension, metric: 'cosine' })`).
|
|
2896
|
+
* Embeddings you pass to `storeFact` / `recordEvent` / `learnProcedure`
|
|
2897
|
+
* must match that collection dimension.
|
|
2898
|
+
*/
|
|
2893
2899
|
get dimension() {
|
|
2894
2900
|
return this.config?.dimension ?? 384;
|
|
2895
2901
|
}
|
|
@@ -2901,7 +2907,7 @@ var AgentMemoryClient = class {
|
|
|
2901
2907
|
async searchFacts(collection, embedding, k = 5) {
|
|
2902
2908
|
return this.backend.searchSemanticMemory(collection, embedding, k);
|
|
2903
2909
|
}
|
|
2904
|
-
/** Record an episodic event */
|
|
2910
|
+
/** Record an episodic event. Returns the generated point ID. */
|
|
2905
2911
|
async recordEvent(collection, event) {
|
|
2906
2912
|
return this.backend.recordEpisodicEvent(collection, event);
|
|
2907
2913
|
}
|
|
@@ -2909,7 +2915,7 @@ var AgentMemoryClient = class {
|
|
|
2909
2915
|
async recallEvents(collection, embedding, k = 5) {
|
|
2910
2916
|
return this.backend.recallEpisodicEvents(collection, embedding, k);
|
|
2911
2917
|
}
|
|
2912
|
-
/** Store a procedural pattern */
|
|
2918
|
+
/** Store a procedural pattern. Returns the generated point ID. */
|
|
2913
2919
|
async learnProcedure(collection, pattern) {
|
|
2914
2920
|
return this.backend.storeProceduralPattern(collection, pattern);
|
|
2915
2921
|
}
|
|
@@ -2917,6 +2923,10 @@ var AgentMemoryClient = class {
|
|
|
2917
2923
|
async recallProcedures(collection, embedding, k = 5) {
|
|
2918
2924
|
return this.backend.matchProceduralPatterns(collection, embedding, k);
|
|
2919
2925
|
}
|
|
2926
|
+
/** Delete a memory entry (fact, event, or procedure) by its point ID. */
|
|
2927
|
+
async deleteMemory(collection, id) {
|
|
2928
|
+
return this.backend.delete(collection, id);
|
|
2929
|
+
}
|
|
2920
2930
|
};
|
|
2921
2931
|
|
|
2922
2932
|
// src/client/validation.ts
|
|
@@ -2939,7 +2949,8 @@ function validateDocsBatch(docs, validateDoc) {
|
|
|
2939
2949
|
}
|
|
2940
2950
|
}
|
|
2941
2951
|
function validateDocument(doc, config) {
|
|
2942
|
-
|
|
2952
|
+
const id = doc.id;
|
|
2953
|
+
if (id === void 0 || id === null) {
|
|
2943
2954
|
throw new ValidationError("Document ID is required");
|
|
2944
2955
|
}
|
|
2945
2956
|
requireVector(doc.vector, "Vector");
|
|
@@ -2994,11 +3005,15 @@ function trainPq2(backend, collection, options) {
|
|
|
2994
3005
|
return backend.trainPq(collection, options);
|
|
2995
3006
|
}
|
|
2996
3007
|
function streamInsert2(backend, config, collection, docs) {
|
|
2997
|
-
validateDocsBatch(docs, (doc) =>
|
|
3008
|
+
validateDocsBatch(docs, (doc) => {
|
|
3009
|
+
validateDocument(doc, config);
|
|
3010
|
+
});
|
|
2998
3011
|
return backend.streamInsert(collection, docs);
|
|
2999
3012
|
}
|
|
3000
3013
|
function streamUpsertPoints2(backend, config, collection, docs) {
|
|
3001
|
-
validateDocsBatch(docs, (doc) =>
|
|
3014
|
+
validateDocsBatch(docs, (doc) => {
|
|
3015
|
+
validateDocument(doc, config);
|
|
3016
|
+
});
|
|
3002
3017
|
return backend.streamUpsertPoints(collection, docs);
|
|
3003
3018
|
}
|
|
3004
3019
|
function scroll2(backend, collection, request2) {
|
|
@@ -3051,12 +3066,15 @@ function aggregate2(backend, queryString, params, options) {
|
|
|
3051
3066
|
}
|
|
3052
3067
|
|
|
3053
3068
|
// src/client/graph-methods.ts
|
|
3069
|
+
function isGraphNodeId(value) {
|
|
3070
|
+
return typeof value === "number" || typeof value === "string";
|
|
3071
|
+
}
|
|
3054
3072
|
function addEdge2(backend, collection, edge) {
|
|
3055
3073
|
if (!edge.label || typeof edge.label !== "string") {
|
|
3056
3074
|
throw new ValidationError("Edge label is required and must be a string");
|
|
3057
3075
|
}
|
|
3058
|
-
if (
|
|
3059
|
-
throw new ValidationError("Edge source and target must be numbers");
|
|
3076
|
+
if (!isGraphNodeId(edge.source) || !isGraphNodeId(edge.target)) {
|
|
3077
|
+
throw new ValidationError("Edge source and target must be numbers or strings");
|
|
3060
3078
|
}
|
|
3061
3079
|
return backend.addEdge(collection, edge);
|
|
3062
3080
|
}
|
|
@@ -3064,8 +3082,8 @@ function getEdges2(backend, collection, options) {
|
|
|
3064
3082
|
return backend.getEdges(collection, options);
|
|
3065
3083
|
}
|
|
3066
3084
|
function traverseGraph2(backend, collection, request2) {
|
|
3067
|
-
if (
|
|
3068
|
-
throw new ValidationError("Source node ID must be a number");
|
|
3085
|
+
if (!isGraphNodeId(request2.source)) {
|
|
3086
|
+
throw new ValidationError("Source node ID must be a number or string");
|
|
3069
3087
|
}
|
|
3070
3088
|
if (request2.strategy && !["bfs", "dfs"].includes(request2.strategy)) {
|
|
3071
3089
|
throw new ValidationError("Strategy must be 'bfs' or 'dfs'");
|
|
@@ -3076,6 +3094,9 @@ function traverseParallel2(backend, collection, request2) {
|
|
|
3076
3094
|
if (!Array.isArray(request2.sources) || request2.sources.length === 0) {
|
|
3077
3095
|
throw new ValidationError("At least one source node ID is required");
|
|
3078
3096
|
}
|
|
3097
|
+
if (!request2.sources.every(isGraphNodeId)) {
|
|
3098
|
+
throw new ValidationError("Source node IDs must be numbers or strings");
|
|
3099
|
+
}
|
|
3079
3100
|
return backend.traverseParallel(collection, request2);
|
|
3080
3101
|
}
|
|
3081
3102
|
function getNodeDegree2(backend, collection, nodeId) {
|
|
@@ -3131,13 +3152,14 @@ var VelesDB = class {
|
|
|
3131
3152
|
this.backend = this.createBackend(config);
|
|
3132
3153
|
}
|
|
3133
3154
|
validateConfig(config) {
|
|
3134
|
-
|
|
3155
|
+
const backend = config.backend;
|
|
3156
|
+
if (!backend) {
|
|
3135
3157
|
throw new ValidationError("Backend type is required");
|
|
3136
3158
|
}
|
|
3137
|
-
if (
|
|
3138
|
-
throw new ValidationError(`Invalid backend type: ${
|
|
3159
|
+
if (backend !== "wasm" && backend !== "rest") {
|
|
3160
|
+
throw new ValidationError(`Invalid backend type: ${backend}. Use 'wasm' or 'rest'`);
|
|
3139
3161
|
}
|
|
3140
|
-
if (
|
|
3162
|
+
if (backend === "rest" && !config.url) {
|
|
3141
3163
|
throw new ValidationError("URL is required for REST backend");
|
|
3142
3164
|
}
|
|
3143
3165
|
}
|
|
@@ -3145,10 +3167,14 @@ var VelesDB = class {
|
|
|
3145
3167
|
switch (config.backend) {
|
|
3146
3168
|
case "wasm":
|
|
3147
3169
|
return new WasmBackend();
|
|
3148
|
-
case "rest":
|
|
3170
|
+
case "rest": {
|
|
3171
|
+
if (!config.url) {
|
|
3172
|
+
throw new ValidationError("URL is required for REST backend");
|
|
3173
|
+
}
|
|
3149
3174
|
return new RestBackend(config.url, config.apiKey, config.timeout);
|
|
3175
|
+
}
|
|
3150
3176
|
default:
|
|
3151
|
-
throw new ValidationError(`Unknown backend: ${config.backend}`);
|
|
3177
|
+
throw new ValidationError(`Unknown backend: ${String(config.backend)}`);
|
|
3152
3178
|
}
|
|
3153
3179
|
}
|
|
3154
3180
|
/** Initialize the client. Must be called before any other operations. */
|
|
@@ -3207,7 +3233,9 @@ var VelesDB = class {
|
|
|
3207
3233
|
}
|
|
3208
3234
|
async upsertBatch(collection, docs) {
|
|
3209
3235
|
this.ensureInitialized();
|
|
3210
|
-
validateDocsBatch(docs, (doc) =>
|
|
3236
|
+
validateDocsBatch(docs, (doc) => {
|
|
3237
|
+
validateDocument(doc, this.config);
|
|
3238
|
+
});
|
|
3211
3239
|
await this.backend.upsertBatch(collection, docs);
|
|
3212
3240
|
}
|
|
3213
3241
|
async delete(collection, id) {
|
|
@@ -3723,13 +3751,14 @@ var VelesQLBuilder = class _VelesQLBuilder {
|
|
|
3723
3751
|
return `*${min}..${max}`;
|
|
3724
3752
|
}
|
|
3725
3753
|
buildWhereClause() {
|
|
3726
|
-
|
|
3727
|
-
const
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3754
|
+
let result = "";
|
|
3755
|
+
for (const [idx, clause] of this.state.whereClauses.entries()) {
|
|
3756
|
+
if (idx === 0) {
|
|
3757
|
+
if (!clause) return "";
|
|
3758
|
+
result = clause;
|
|
3759
|
+
continue;
|
|
3760
|
+
}
|
|
3761
|
+
const operator = this.state.whereOperators[idx - 1] ?? "AND";
|
|
3733
3762
|
if (clause) {
|
|
3734
3763
|
result += ` ${operator} ${clause}`;
|
|
3735
3764
|
}
|
|
@@ -3743,13 +3772,14 @@ function velesql() {
|
|
|
3743
3772
|
|
|
3744
3773
|
// src/filter.ts
|
|
3745
3774
|
function isTypedFilter(input) {
|
|
3746
|
-
|
|
3775
|
+
const value = input;
|
|
3776
|
+
if (typeof value !== "object" || value === null) {
|
|
3747
3777
|
return false;
|
|
3748
3778
|
}
|
|
3749
|
-
if (!("condition" in
|
|
3779
|
+
if (!("condition" in value)) {
|
|
3750
3780
|
return false;
|
|
3751
3781
|
}
|
|
3752
|
-
const cond =
|
|
3782
|
+
const cond = value.condition;
|
|
3753
3783
|
return typeof cond === "object" && cond !== null;
|
|
3754
3784
|
}
|
|
3755
3785
|
function normalizeFilter(input) {
|
|
@@ -3884,6 +3914,47 @@ var f = {
|
|
|
3884
3914
|
return { condition: { type: "not", condition: filter.condition } };
|
|
3885
3915
|
}
|
|
3886
3916
|
};
|
|
3917
|
+
|
|
3918
|
+
// src/embed.ts
|
|
3919
|
+
var OpenAIEmbedder = class {
|
|
3920
|
+
constructor(options) {
|
|
3921
|
+
this.model = options.model ?? "text-embedding-3-small";
|
|
3922
|
+
this.apiKey = options.apiKey;
|
|
3923
|
+
this.baseUrl = options.baseUrl?.replace(/\/$/, "") ?? "https://api.openai.com/v1";
|
|
3924
|
+
this.requestedDimensions = options.dimensions;
|
|
3925
|
+
this.dimension = options.dimensions ?? 0;
|
|
3926
|
+
}
|
|
3927
|
+
async embed(texts) {
|
|
3928
|
+
if (texts.length === 0) return [];
|
|
3929
|
+
const body = { model: this.model, input: texts };
|
|
3930
|
+
if (this.requestedDimensions !== void 0) {
|
|
3931
|
+
body["dimensions"] = this.requestedDimensions;
|
|
3932
|
+
}
|
|
3933
|
+
const response = await fetch(`${this.baseUrl}/embeddings`, {
|
|
3934
|
+
method: "POST",
|
|
3935
|
+
headers: {
|
|
3936
|
+
"Content-Type": "application/json",
|
|
3937
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
3938
|
+
},
|
|
3939
|
+
body: JSON.stringify(body)
|
|
3940
|
+
});
|
|
3941
|
+
if (!response.ok) {
|
|
3942
|
+
const text = await response.text().catch(() => "");
|
|
3943
|
+
throw new Error(
|
|
3944
|
+
`OpenAI embeddings request failed: ${response.status} ${response.statusText} \u2014 ${text.slice(0, 500)}`
|
|
3945
|
+
);
|
|
3946
|
+
}
|
|
3947
|
+
const json = await response.json();
|
|
3948
|
+
const vectors = json.data.map((item) => item.embedding);
|
|
3949
|
+
if (this.dimension === 0) {
|
|
3950
|
+
for (const vec of vectors) {
|
|
3951
|
+
this.dimension = vec.length;
|
|
3952
|
+
break;
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
return vectors;
|
|
3956
|
+
}
|
|
3957
|
+
};
|
|
3887
3958
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3888
3959
|
0 && (module.exports = {
|
|
3889
3960
|
AgentMemoryClient,
|
|
@@ -3914,6 +3985,7 @@ var f = {
|
|
|
3914
3985
|
IoError,
|
|
3915
3986
|
NodeNotFoundError,
|
|
3916
3987
|
NotFoundError,
|
|
3988
|
+
OpenAIEmbedder,
|
|
3917
3989
|
OverflowError,
|
|
3918
3990
|
PointNotFoundError,
|
|
3919
3991
|
QueryError,
|