@agentuity/vector 1.0.54
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/AGENTS.md +43 -0
- package/README.md +56 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/src/index.ts +144 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Agent Guidelines for @agentuity/vector
|
|
2
|
+
|
|
3
|
+
## Package Overview
|
|
4
|
+
|
|
5
|
+
Standalone package for the Agentuity Vector storage service. Provides a simple, ergonomic client for storing and searching vector embeddings.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
- **Build**: `bun run build`
|
|
10
|
+
- **Typecheck**: `bun run typecheck`
|
|
11
|
+
- **Clean**: `rm -rf dist`
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
- **Runtime**: Node.js and Bun compatible
|
|
16
|
+
- **Exports**: VectorClient and all types from @agentuity/core/vector
|
|
17
|
+
- **Dependencies**: @agentuity/core, zod
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { VectorClient } from '@agentuity/vector';
|
|
23
|
+
|
|
24
|
+
const client = new VectorClient();
|
|
25
|
+
|
|
26
|
+
// Upsert vectors with automatic embedding
|
|
27
|
+
await client.upsert('products', {
|
|
28
|
+
key: 'chair-001',
|
|
29
|
+
document: 'Comfortable office chair with lumbar support',
|
|
30
|
+
metadata: { category: 'furniture' }
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Search for similar vectors
|
|
34
|
+
const results = await client.search('products', {
|
|
35
|
+
query: 'office seating',
|
|
36
|
+
limit: 5
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Publishing
|
|
41
|
+
|
|
42
|
+
1. Run `bun run build`
|
|
43
|
+
2. Must publish **after** @agentuity/core
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @agentuity/vector
|
|
2
|
+
|
|
3
|
+
A standalone package for the Agentuity Vector storage service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @agentuity/vector
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { VectorClient } from '@agentuity/vector';
|
|
15
|
+
|
|
16
|
+
const client = new VectorClient();
|
|
17
|
+
|
|
18
|
+
// Upsert vectors with automatic embedding
|
|
19
|
+
await client.upsert('products', {
|
|
20
|
+
key: 'chair-001',
|
|
21
|
+
document: 'Comfortable office chair with lumbar support',
|
|
22
|
+
metadata: { category: 'furniture', price: 299 }
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Search for similar vectors
|
|
26
|
+
const results = await client.search('products', {
|
|
27
|
+
query: 'office seating',
|
|
28
|
+
limit: 5,
|
|
29
|
+
similarity: 0.7
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
for (const result of results) {
|
|
33
|
+
console.log(`${result.key}: ${result.similarity * 100}% match`);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const client = new VectorClient({
|
|
41
|
+
apiKey: 'your-api-key',
|
|
42
|
+
url: 'https://api.agentuity.com',
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Environment Variables
|
|
47
|
+
|
|
48
|
+
| Variable | Description | Default |
|
|
49
|
+
|----------|-------------|---------|
|
|
50
|
+
| `AGENTUITY_SDK_KEY` | API key for authentication | Required |
|
|
51
|
+
| `AGENTUITY_REGION` | Region for API endpoints | `usc` |
|
|
52
|
+
| `AGENTUITY_VECTOR_URL` | Override Vector API URL | Auto-detected |
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export { VectorStorageService, VectorStorage, type VectorUpsertParams, type VectorUpsertBase, type VectorUpsertEmbeddings, type VectorUpsertText, type VectorUpsertResult, type VectorSearchParams, type VectorSearchResult, type VectorSearchResultWithDocument, type VectorResult, type VectorResultFound, type VectorResultNotFound, type VectorNamespaceStats, type VectorNamespaceStatsWithSamples, type VectorItemStats, type VectorGetAllStatsParams, type VectorStatsPaginated, type VectorSortField, VECTOR_MIN_TTL_SECONDS, VECTOR_MAX_TTL_SECONDS, VECTOR_DEFAULT_TTL_SECONDS, VectorUpsertBaseSchema, VectorUpsertEmbeddingsSchema, VectorUpsertTextSchema, VectorUpsertParamsSchema, VectorSearchParamsSchema, VectorSearchResultSchema, VectorSearchResultWithDocumentSchema, VectorUpsertResultSchema, VectorResultFoundSchema, VectorResultNotFoundSchema, VectorResultSchema, VectorNamespaceStatsSchema, VectorNamespaceStatsWithSamplesSchema, VectorItemStatsSchema, VectorGetAllStatsParamsSchema, VectorStatsPaginatedSchema, VectorSortFieldSchema, } from '@agentuity/core/vector';
|
|
2
|
+
import { VectorStorageService, type VectorUpsertParams, type VectorSearchParams, type VectorResult, type VectorSearchResult, type VectorSearchResultWithDocument, type VectorUpsertResult } from '@agentuity/core/vector';
|
|
3
|
+
import { type Logger } from '@agentuity/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare const VectorClientOptionsSchema: z.ZodObject<{
|
|
6
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
7
|
+
url: z.ZodOptional<z.ZodString>;
|
|
8
|
+
orgId: z.ZodOptional<z.ZodString>;
|
|
9
|
+
logger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export type VectorClientOptions = z.infer<typeof VectorClientOptionsSchema>;
|
|
12
|
+
export declare class VectorClient {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(options?: VectorClientOptions);
|
|
15
|
+
upsert(name: string, ...documents: VectorUpsertParams[]): Promise<VectorUpsertResult[]>;
|
|
16
|
+
get<T extends Record<string, unknown> = Record<string, unknown>>(name: string, key: string): Promise<VectorResult<T>>;
|
|
17
|
+
getMany<T extends Record<string, unknown> = Record<string, unknown>>(name: string, ...keys: string[]): Promise<Map<string, VectorSearchResultWithDocument<T>>>;
|
|
18
|
+
search<T extends Record<string, unknown> = Record<string, unknown>>(name: string, params: VectorSearchParams<T>): Promise<VectorSearchResult<T>[]>;
|
|
19
|
+
delete(name: string, ...keys: string[]): Promise<number>;
|
|
20
|
+
exists(name: string): Promise<boolean>;
|
|
21
|
+
getStats(name: string): Promise<{
|
|
22
|
+
sum: number;
|
|
23
|
+
count: number;
|
|
24
|
+
createdAt?: number | undefined;
|
|
25
|
+
lastUsed?: number | undefined;
|
|
26
|
+
internal?: boolean | undefined;
|
|
27
|
+
sampledResults?: Record<string, {
|
|
28
|
+
size: number;
|
|
29
|
+
firstUsed: number;
|
|
30
|
+
lastUsed: number;
|
|
31
|
+
embedding?: number[] | undefined;
|
|
32
|
+
document?: string | undefined;
|
|
33
|
+
metadata?: Record<string, unknown> | undefined;
|
|
34
|
+
count?: number | undefined;
|
|
35
|
+
expiresAt?: string | undefined;
|
|
36
|
+
}> | undefined;
|
|
37
|
+
}>;
|
|
38
|
+
getAllStats(params?: Parameters<VectorStorageService['getAllStats']>[0]): Promise<Record<string, {
|
|
39
|
+
sum: number;
|
|
40
|
+
count: number;
|
|
41
|
+
createdAt?: number | undefined;
|
|
42
|
+
lastUsed?: number | undefined;
|
|
43
|
+
internal?: boolean | undefined;
|
|
44
|
+
}> | {
|
|
45
|
+
namespaces: Record<string, {
|
|
46
|
+
sum: number;
|
|
47
|
+
count: number;
|
|
48
|
+
createdAt?: number | undefined;
|
|
49
|
+
lastUsed?: number | undefined;
|
|
50
|
+
internal?: boolean | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
total: number;
|
|
53
|
+
limit: number;
|
|
54
|
+
offset: number;
|
|
55
|
+
hasMore: boolean;
|
|
56
|
+
}>;
|
|
57
|
+
getNamespaces(): Promise<string[]>;
|
|
58
|
+
deleteNamespace(name: string): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,8BAA8B,EACnC,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,+BAA+B,EACpC,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,oCAAoC,EACpC,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,0BAA0B,EAC1B,qCAAqC,EACrC,qBAAqB,EACrB,6BAA6B,EAC7B,0BAA0B,EAC1B,qBAAqB,GACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACN,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,8BAA8B,EACnC,KAAK,kBAAkB,EACvB,MAAM,wBAAwB,CAAC;AA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G,OAAO,CAAC,OAAO,CAAC;IAItC,QAAQ,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;;;;;;;IAIrB,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;IAIvE,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIlC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export { VectorStorageService, VECTOR_MIN_TTL_SECONDS, VECTOR_MAX_TTL_SECONDS, VECTOR_DEFAULT_TTL_SECONDS, VectorUpsertBaseSchema, VectorUpsertEmbeddingsSchema, VectorUpsertTextSchema, VectorUpsertParamsSchema, VectorSearchParamsSchema, VectorSearchResultSchema, VectorSearchResultWithDocumentSchema, VectorUpsertResultSchema, VectorResultFoundSchema, VectorResultNotFoundSchema, VectorResultSchema, VectorNamespaceStatsSchema, VectorNamespaceStatsWithSamplesSchema, VectorItemStatsSchema, VectorGetAllStatsParamsSchema, VectorStatsPaginatedSchema, VectorSortFieldSchema, } from '@agentuity/core/vector';
|
|
2
|
+
import { VectorStorageService, } from '@agentuity/core/vector';
|
|
3
|
+
import { createServerFetchAdapter, buildClientHeaders } from '@agentuity/server';
|
|
4
|
+
import { createMinimalLogger } from '@agentuity/core';
|
|
5
|
+
import { getEnv } from '@agentuity/core';
|
|
6
|
+
import { getServiceUrls } from '@agentuity/core/config';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
const isLogger = (val) => typeof val === 'object' &&
|
|
9
|
+
val !== null &&
|
|
10
|
+
['info', 'warn', 'error', 'debug', 'trace'].every((m) => typeof val[m] === 'function');
|
|
11
|
+
export const VectorClientOptionsSchema = z.object({
|
|
12
|
+
apiKey: z.string().optional().describe('API key for authentication'),
|
|
13
|
+
url: z.string().optional().describe('Base URL for the Vector API'),
|
|
14
|
+
orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
|
|
15
|
+
logger: z.custom(isLogger).optional().describe('Custom logger instance'),
|
|
16
|
+
});
|
|
17
|
+
export class VectorClient {
|
|
18
|
+
#service;
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
const validatedOptions = VectorClientOptionsSchema.parse(options);
|
|
21
|
+
const apiKey = validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
|
|
22
|
+
const region = getEnv('AGENTUITY_REGION') ?? 'usc';
|
|
23
|
+
const serviceUrls = getServiceUrls(region);
|
|
24
|
+
const url = validatedOptions.url || getEnv('AGENTUITY_VECTOR_URL') || serviceUrls.vector;
|
|
25
|
+
const logger = validatedOptions.logger ?? createMinimalLogger();
|
|
26
|
+
const headers = buildClientHeaders({
|
|
27
|
+
apiKey,
|
|
28
|
+
orgId: validatedOptions.orgId,
|
|
29
|
+
});
|
|
30
|
+
const adapter = createServerFetchAdapter({ headers }, logger);
|
|
31
|
+
this.#service = new VectorStorageService(url, adapter);
|
|
32
|
+
}
|
|
33
|
+
async upsert(name, ...documents) {
|
|
34
|
+
return this.#service.upsert(name, ...documents);
|
|
35
|
+
}
|
|
36
|
+
async get(name, key) {
|
|
37
|
+
return this.#service.get(name, key);
|
|
38
|
+
}
|
|
39
|
+
async getMany(name, ...keys) {
|
|
40
|
+
return this.#service.getMany(name, ...keys);
|
|
41
|
+
}
|
|
42
|
+
async search(name, params) {
|
|
43
|
+
return this.#service.search(name, params);
|
|
44
|
+
}
|
|
45
|
+
async delete(name, ...keys) {
|
|
46
|
+
return this.#service.delete(name, ...keys);
|
|
47
|
+
}
|
|
48
|
+
async exists(name) {
|
|
49
|
+
return this.#service.exists(name);
|
|
50
|
+
}
|
|
51
|
+
async getStats(name) {
|
|
52
|
+
return this.#service.getStats(name);
|
|
53
|
+
}
|
|
54
|
+
async getAllStats(params) {
|
|
55
|
+
return this.#service.getAllStats(params);
|
|
56
|
+
}
|
|
57
|
+
async getNamespaces() {
|
|
58
|
+
return this.#service.getNamespaces();
|
|
59
|
+
}
|
|
60
|
+
async deleteNamespace(name) {
|
|
61
|
+
return this.#service.deleteNamespace(name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EAmBpB,sBAAsB,EACtB,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,oCAAoC,EACpC,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,0BAA0B,EAC1B,qCAAqC,EACrC,qBAAqB,EACrB,6BAA6B,EAC7B,0BAA0B,EAC1B,qBAAqB,GACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACN,oBAAoB,GAOpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAe,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAiB,EAAE,CAChD,OAAO,GAAG,KAAK,QAAQ;IACvB,GAAG,KAAK,IAAI;IACZ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,CAChD,CAAC,CAAC,EAAE,EAAE,CAAC,OAAQ,GAA+B,CA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;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAAY;QACjC,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentuity/vector",
|
|
3
|
+
"version": "1.0.54",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"author": "Agentuity employees and contributors",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"AGENTS.md",
|
|
11
|
+
"README.md",
|
|
12
|
+
"src",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
23
|
+
"build": "bunx tsc --build --force",
|
|
24
|
+
"typecheck": "bunx tsc --noEmit",
|
|
25
|
+
"prepublishOnly": "bun run clean && bun run build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@agentuity/core": "1.0.54",
|
|
29
|
+
"@agentuity/server": "1.0.54",
|
|
30
|
+
"zod": "^4.3.5"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/bun": "latest",
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"bun-types": "latest",
|
|
36
|
+
"typescript": "^5.9.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export {
|
|
2
|
+
VectorStorageService,
|
|
3
|
+
VectorStorage,
|
|
4
|
+
type VectorUpsertParams,
|
|
5
|
+
type VectorUpsertBase,
|
|
6
|
+
type VectorUpsertEmbeddings,
|
|
7
|
+
type VectorUpsertText,
|
|
8
|
+
type VectorUpsertResult,
|
|
9
|
+
type VectorSearchParams,
|
|
10
|
+
type VectorSearchResult,
|
|
11
|
+
type VectorSearchResultWithDocument,
|
|
12
|
+
type VectorResult,
|
|
13
|
+
type VectorResultFound,
|
|
14
|
+
type VectorResultNotFound,
|
|
15
|
+
type VectorNamespaceStats,
|
|
16
|
+
type VectorNamespaceStatsWithSamples,
|
|
17
|
+
type VectorItemStats,
|
|
18
|
+
type VectorGetAllStatsParams,
|
|
19
|
+
type VectorStatsPaginated,
|
|
20
|
+
type VectorSortField,
|
|
21
|
+
VECTOR_MIN_TTL_SECONDS,
|
|
22
|
+
VECTOR_MAX_TTL_SECONDS,
|
|
23
|
+
VECTOR_DEFAULT_TTL_SECONDS,
|
|
24
|
+
VectorUpsertBaseSchema,
|
|
25
|
+
VectorUpsertEmbeddingsSchema,
|
|
26
|
+
VectorUpsertTextSchema,
|
|
27
|
+
VectorUpsertParamsSchema,
|
|
28
|
+
VectorSearchParamsSchema,
|
|
29
|
+
VectorSearchResultSchema,
|
|
30
|
+
VectorSearchResultWithDocumentSchema,
|
|
31
|
+
VectorUpsertResultSchema,
|
|
32
|
+
VectorResultFoundSchema,
|
|
33
|
+
VectorResultNotFoundSchema,
|
|
34
|
+
VectorResultSchema,
|
|
35
|
+
VectorNamespaceStatsSchema,
|
|
36
|
+
VectorNamespaceStatsWithSamplesSchema,
|
|
37
|
+
VectorItemStatsSchema,
|
|
38
|
+
VectorGetAllStatsParamsSchema,
|
|
39
|
+
VectorStatsPaginatedSchema,
|
|
40
|
+
VectorSortFieldSchema,
|
|
41
|
+
} from '@agentuity/core/vector';
|
|
42
|
+
|
|
43
|
+
import {
|
|
44
|
+
VectorStorageService,
|
|
45
|
+
type VectorUpsertParams,
|
|
46
|
+
type VectorSearchParams,
|
|
47
|
+
type VectorResult,
|
|
48
|
+
type VectorSearchResult,
|
|
49
|
+
type VectorSearchResultWithDocument,
|
|
50
|
+
type VectorUpsertResult,
|
|
51
|
+
} from '@agentuity/core/vector';
|
|
52
|
+
import { createServerFetchAdapter, buildClientHeaders, type Logger } from '@agentuity/server';
|
|
53
|
+
import { createMinimalLogger } from '@agentuity/core';
|
|
54
|
+
import { getEnv } from '@agentuity/core';
|
|
55
|
+
import { getServiceUrls } from '@agentuity/core/config';
|
|
56
|
+
import { z } from 'zod';
|
|
57
|
+
|
|
58
|
+
const isLogger = (val: unknown): val is Logger =>
|
|
59
|
+
typeof val === 'object' &&
|
|
60
|
+
val !== null &&
|
|
61
|
+
['info', 'warn', 'error', 'debug', 'trace'].every(
|
|
62
|
+
(m) => typeof (val as Record<string, unknown>)[m] === 'function'
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
export const VectorClientOptionsSchema = z.object({
|
|
66
|
+
apiKey: z.string().optional().describe('API key for authentication'),
|
|
67
|
+
url: z.string().optional().describe('Base URL for the Vector API'),
|
|
68
|
+
orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
|
|
69
|
+
logger: z.custom<Logger>(isLogger).optional().describe('Custom logger instance'),
|
|
70
|
+
});
|
|
71
|
+
export type VectorClientOptions = z.infer<typeof VectorClientOptionsSchema>;
|
|
72
|
+
|
|
73
|
+
export class VectorClient {
|
|
74
|
+
readonly #service: VectorStorageService;
|
|
75
|
+
|
|
76
|
+
constructor(options: VectorClientOptions = {}) {
|
|
77
|
+
const validatedOptions = VectorClientOptionsSchema.parse(options);
|
|
78
|
+
const apiKey =
|
|
79
|
+
validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
|
|
80
|
+
const region = getEnv('AGENTUITY_REGION') ?? 'usc';
|
|
81
|
+
const serviceUrls = getServiceUrls(region);
|
|
82
|
+
|
|
83
|
+
const url = validatedOptions.url || getEnv('AGENTUITY_VECTOR_URL') || serviceUrls.vector;
|
|
84
|
+
|
|
85
|
+
const logger = validatedOptions.logger ?? createMinimalLogger();
|
|
86
|
+
|
|
87
|
+
const headers = buildClientHeaders({
|
|
88
|
+
apiKey,
|
|
89
|
+
orgId: validatedOptions.orgId,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const adapter = createServerFetchAdapter({ headers }, logger);
|
|
93
|
+
this.#service = new VectorStorageService(url, adapter);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async upsert(name: string, ...documents: VectorUpsertParams[]): Promise<VectorUpsertResult[]> {
|
|
97
|
+
return this.#service.upsert(name, ...documents);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async get<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
101
|
+
name: string,
|
|
102
|
+
key: string
|
|
103
|
+
): Promise<VectorResult<T>> {
|
|
104
|
+
return this.#service.get(name, key);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async getMany<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
108
|
+
name: string,
|
|
109
|
+
...keys: string[]
|
|
110
|
+
): Promise<Map<string, VectorSearchResultWithDocument<T>>> {
|
|
111
|
+
return this.#service.getMany(name, ...keys);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async search<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
115
|
+
name: string,
|
|
116
|
+
params: VectorSearchParams<T>
|
|
117
|
+
): Promise<VectorSearchResult<T>[]> {
|
|
118
|
+
return this.#service.search(name, params);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async delete(name: string, ...keys: string[]): Promise<number> {
|
|
122
|
+
return this.#service.delete(name, ...keys);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async exists(name: string): Promise<boolean> {
|
|
126
|
+
return this.#service.exists(name);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async getStats(name: string) {
|
|
130
|
+
return this.#service.getStats(name);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async getAllStats(params?: Parameters<VectorStorageService['getAllStats']>[0]) {
|
|
134
|
+
return this.#service.getAllStats(params);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getNamespaces(): Promise<string[]> {
|
|
138
|
+
return this.#service.getNamespaces();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async deleteNamespace(name: string): Promise<void> {
|
|
142
|
+
return this.#service.deleteNamespace(name);
|
|
143
|
+
}
|
|
144
|
+
}
|