@fluxsoft/fluxvector 0.1.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.
@@ -0,0 +1,337 @@
1
+ interface FluxVectorConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ maxRetries?: number;
5
+ timeout?: number;
6
+ }
7
+ type FilterOperator = '$eq' | '$ne' | '$gt' | '$gte' | '$lt' | '$lte' | '$in' | '$nin';
8
+ type FilterValue = string | number | boolean | string[] | number[];
9
+ type FilterCondition = {
10
+ [K in FilterOperator]?: FilterValue;
11
+ };
12
+ type MetadataFilter = {
13
+ [field: string]: FilterCondition | FilterValue;
14
+ };
15
+ interface CreateCollectionParams {
16
+ name: string;
17
+ dimension?: number;
18
+ metric?: 'cosine' | 'euclidean' | 'dotproduct';
19
+ description?: string;
20
+ }
21
+ interface Collection {
22
+ name: string;
23
+ dimension: number;
24
+ metric: string;
25
+ description: string;
26
+ vectors_count: number;
27
+ created_at: string;
28
+ updated_at: string;
29
+ }
30
+ interface ListCollectionsParams {
31
+ cursor?: string;
32
+ limit?: number;
33
+ }
34
+ interface ListCollectionsResponse {
35
+ data: Collection[];
36
+ has_more: boolean;
37
+ next_cursor: string | null;
38
+ }
39
+ interface VectorInput {
40
+ id: string;
41
+ text?: string;
42
+ values?: number[];
43
+ metadata?: Record<string, unknown>;
44
+ }
45
+ interface Vector {
46
+ id: string;
47
+ text?: string;
48
+ values?: number[];
49
+ metadata?: Record<string, unknown>;
50
+ }
51
+ interface UpsertResponse {
52
+ upserted: number;
53
+ }
54
+ interface QueryParams {
55
+ collection: string;
56
+ text?: string;
57
+ vector?: number[];
58
+ top_k?: number;
59
+ filter?: MetadataFilter;
60
+ include_metadata?: boolean;
61
+ include_text?: boolean;
62
+ mode?: string;
63
+ }
64
+ interface QueryResult {
65
+ id: string;
66
+ score: number;
67
+ text?: string;
68
+ metadata?: Record<string, unknown>;
69
+ values?: number[];
70
+ }
71
+ interface QueryResponse {
72
+ results: QueryResult[];
73
+ usage: UsageInfo;
74
+ took_ms: number;
75
+ }
76
+ interface DeleteVectorsParams {
77
+ collection: string;
78
+ ids?: string[];
79
+ filter?: MetadataFilter;
80
+ }
81
+ interface FetchVectorsParams {
82
+ ids: string[];
83
+ collection: string;
84
+ }
85
+ interface FetchVectorsResponse {
86
+ vectors: Vector[];
87
+ }
88
+ interface SearchParams {
89
+ collection: string;
90
+ text: string;
91
+ top_k?: number;
92
+ filter?: MetadataFilter;
93
+ mode?: string;
94
+ }
95
+ interface SearchResponse {
96
+ results: QueryResult[];
97
+ usage: UsageInfo;
98
+ took_ms: number;
99
+ }
100
+ interface EmbedResponse {
101
+ embedding: number[];
102
+ dimension: number;
103
+ model: string;
104
+ }
105
+ interface EmbedBatchResponse {
106
+ embeddings: number[][];
107
+ dimension: number;
108
+ model: string;
109
+ }
110
+ interface CreateApiKeyParams {
111
+ name: string;
112
+ env?: 'live' | 'test';
113
+ }
114
+ interface ApiKey {
115
+ id: string;
116
+ key?: string;
117
+ prefix: string;
118
+ name: string;
119
+ env: string;
120
+ warning?: string;
121
+ created_at?: string;
122
+ }
123
+ interface UpdateApiKeyParams {
124
+ name: string;
125
+ }
126
+ interface ListApiKeysResponse {
127
+ data: ApiKey[];
128
+ }
129
+ interface UsageInfo {
130
+ embeddings?: number;
131
+ [key: string]: unknown;
132
+ }
133
+ interface UsageOverview {
134
+ plan: string;
135
+ period_start: string;
136
+ requests: number;
137
+ embeddings: number;
138
+ vectors_stored: number;
139
+ collections: number;
140
+ }
141
+ interface UsageHistoryParams {
142
+ days?: number;
143
+ }
144
+ interface UsageHistoryEntry {
145
+ date: string;
146
+ requests: number;
147
+ embeddings: number;
148
+ vectors: number;
149
+ }
150
+ interface UsageHistoryResponse {
151
+ data: UsageHistoryEntry[];
152
+ }
153
+ interface RequestOptions {
154
+ method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
155
+ path: string;
156
+ body?: unknown;
157
+ query?: Record<string, string | number | undefined>;
158
+ }
159
+
160
+ declare class HttpClient {
161
+ private readonly config;
162
+ constructor(config: {
163
+ apiKey: string;
164
+ baseUrl?: string;
165
+ maxRetries?: number;
166
+ timeout?: number;
167
+ });
168
+ request<T>(options: RequestOptions): Promise<T>;
169
+ private buildUrl;
170
+ private buildError;
171
+ private safeJson;
172
+ private getRetryDelay;
173
+ private sleep;
174
+ }
175
+
176
+ declare class Collections {
177
+ private readonly client;
178
+ constructor(client: HttpClient);
179
+ /**
180
+ * Create a new collection.
181
+ */
182
+ create(params: CreateCollectionParams): Promise<Collection>;
183
+ /**
184
+ * List all collections with cursor-based pagination.
185
+ */
186
+ list(params?: ListCollectionsParams): Promise<ListCollectionsResponse>;
187
+ /**
188
+ * Get a collection by name.
189
+ */
190
+ get(name: string): Promise<Collection>;
191
+ /**
192
+ * Delete a collection by name.
193
+ */
194
+ delete(name: string): Promise<{
195
+ deleted: true;
196
+ }>;
197
+ }
198
+
199
+ declare class Vectors {
200
+ private readonly client;
201
+ constructor(client: HttpClient);
202
+ /**
203
+ * Upsert vectors into a collection.
204
+ * Automatically chunks into batches of 1000 vectors.
205
+ */
206
+ upsert(collection: string, vectors: VectorInput[]): Promise<UpsertResponse>;
207
+ /**
208
+ * Query vectors by text or vector with optional filtering.
209
+ */
210
+ query(params: QueryParams): Promise<QueryResponse>;
211
+ /**
212
+ * Delete vectors by IDs or filter.
213
+ */
214
+ delete(collection: string, options: {
215
+ ids?: string[];
216
+ filter?: MetadataFilter;
217
+ }): Promise<{
218
+ deleted: true;
219
+ }>;
220
+ /**
221
+ * Fetch vectors by their IDs.
222
+ */
223
+ fetch(collection: string, ids: string[]): Promise<FetchVectorsResponse>;
224
+ }
225
+
226
+ interface SearchOptions {
227
+ topK?: number;
228
+ filter?: MetadataFilter;
229
+ mode?: string;
230
+ }
231
+ declare class Search {
232
+ private readonly client;
233
+ constructor(client: HttpClient);
234
+ /**
235
+ * Semantic search across a collection.
236
+ * Returns matching results ranked by relevance.
237
+ */
238
+ query(collection: string, text: string, options?: SearchOptions): Promise<QueryResult[]>;
239
+ /**
240
+ * Semantic search with full response (includes usage and timing).
241
+ */
242
+ queryWithMeta(collection: string, text: string, options?: SearchOptions): Promise<SearchResponse>;
243
+ }
244
+
245
+ declare class Embeddings {
246
+ private readonly client;
247
+ constructor(client: HttpClient);
248
+ /**
249
+ * Generate an embedding for a single text.
250
+ */
251
+ create(text: string): Promise<EmbedResponse>;
252
+ /**
253
+ * Generate embeddings for multiple texts in a single request.
254
+ */
255
+ createBatch(texts: string[]): Promise<EmbedBatchResponse>;
256
+ }
257
+
258
+ declare class ApiKeys {
259
+ private readonly client;
260
+ constructor(client: HttpClient);
261
+ /**
262
+ * Create a new API key.
263
+ */
264
+ create(params: CreateApiKeyParams): Promise<ApiKey>;
265
+ /**
266
+ * List all API keys.
267
+ */
268
+ list(): Promise<ListApiKeysResponse>;
269
+ /**
270
+ * Update an API key's name.
271
+ */
272
+ update(id: string, params: UpdateApiKeyParams): Promise<ApiKey>;
273
+ /**
274
+ * Delete an API key.
275
+ */
276
+ delete(id: string): Promise<{
277
+ deleted: true;
278
+ }>;
279
+ }
280
+
281
+ declare class Usage {
282
+ private readonly client;
283
+ constructor(client: HttpClient);
284
+ /**
285
+ * Get current usage overview for the billing period.
286
+ */
287
+ get(): Promise<UsageOverview>;
288
+ /**
289
+ * Get historical usage data.
290
+ */
291
+ history(params?: UsageHistoryParams): Promise<UsageHistoryResponse>;
292
+ }
293
+
294
+ declare class FluxVectorError extends Error {
295
+ readonly status: number;
296
+ readonly code: string;
297
+ readonly requestId: string | undefined;
298
+ constructor(message: string, status: number, code?: string, requestId?: string);
299
+ }
300
+ declare class AuthenticationError extends FluxVectorError {
301
+ constructor(message?: string, requestId?: string);
302
+ }
303
+ declare class NotFoundError extends FluxVectorError {
304
+ constructor(message?: string, requestId?: string);
305
+ }
306
+ declare class RateLimitError extends FluxVectorError {
307
+ readonly retryAfter: number | undefined;
308
+ constructor(message?: string, retryAfter?: number, requestId?: string);
309
+ }
310
+ declare class ValidationError extends FluxVectorError {
311
+ constructor(message?: string, requestId?: string);
312
+ }
313
+ declare class ServerError extends FluxVectorError {
314
+ constructor(message?: string, status?: number, requestId?: string);
315
+ }
316
+
317
+ declare class FluxVector {
318
+ readonly collections: Collections;
319
+ readonly vectors: Vectors;
320
+ readonly embeddings: Embeddings;
321
+ readonly apiKeys: ApiKeys;
322
+ readonly usage: Usage;
323
+ private readonly searchResource;
324
+ constructor(config: FluxVectorConfig);
325
+ /**
326
+ * Semantic search across a collection.
327
+ *
328
+ * @example
329
+ * const results = await fv.search('products', 'comfortable shoes', {
330
+ * topK: 5,
331
+ * filter: { price: { $lt: 100 } },
332
+ * });
333
+ */
334
+ search(collection: string, text: string, options?: SearchOptions): Promise<QueryResult[]>;
335
+ }
336
+
337
+ export { type ApiKey, ApiKeys, AuthenticationError, type Collection, Collections, type CreateApiKeyParams, type CreateCollectionParams, type DeleteVectorsParams, type EmbedBatchResponse, type EmbedResponse, Embeddings, type FetchVectorsParams, type FetchVectorsResponse, type FilterCondition, type FilterOperator, type FilterValue, FluxVector, type FluxVectorConfig, FluxVectorError, HttpClient, type ListApiKeysResponse, type ListCollectionsParams, type ListCollectionsResponse, type MetadataFilter, NotFoundError, type QueryParams, type QueryResponse, type QueryResult, RateLimitError, Search, type SearchOptions, type SearchParams, type SearchResponse, ServerError, type UpdateApiKeyParams, type UpsertResponse, Usage, type UsageHistoryEntry, type UsageHistoryParams, type UsageHistoryResponse, type UsageInfo, type UsageOverview, ValidationError, type Vector, type VectorInput, Vectors };