praisonai 1.2.1 → 1.2.2
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/cache/index.d.ts +78 -0
- package/dist/cache/index.js +235 -0
- package/dist/db/postgres.d.ts +84 -0
- package/dist/db/postgres.js +266 -0
- package/dist/db/redis.d.ts +109 -0
- package/dist/db/redis.js +307 -0
- package/dist/db/sqlite.d.ts +66 -0
- package/dist/db/sqlite.js +339 -0
- package/dist/events/index.d.ts +84 -0
- package/dist/events/index.js +153 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +84 -1
- package/dist/integrations/index.d.ts +7 -0
- package/dist/integrations/index.js +26 -0
- package/dist/integrations/observability/base.d.ts +123 -0
- package/dist/integrations/observability/base.js +183 -0
- package/dist/integrations/observability/index.d.ts +8 -0
- package/dist/integrations/observability/index.js +29 -0
- package/dist/integrations/observability/langfuse.d.ts +32 -0
- package/dist/integrations/observability/langfuse.js +174 -0
- package/dist/integrations/vector/base.d.ts +110 -0
- package/dist/integrations/vector/base.js +158 -0
- package/dist/integrations/vector/chroma.d.ts +25 -0
- package/dist/integrations/vector/chroma.js +143 -0
- package/dist/integrations/vector/index.d.ts +14 -0
- package/dist/integrations/vector/index.js +37 -0
- package/dist/integrations/vector/pinecone.d.ts +28 -0
- package/dist/integrations/vector/pinecone.js +172 -0
- package/dist/integrations/vector/qdrant.d.ts +25 -0
- package/dist/integrations/vector/qdrant.js +146 -0
- package/dist/integrations/vector/weaviate.d.ts +30 -0
- package/dist/integrations/vector/weaviate.js +206 -0
- package/dist/integrations/voice/base.d.ts +76 -0
- package/dist/integrations/voice/base.js +168 -0
- package/dist/integrations/voice/index.d.ts +6 -0
- package/dist/integrations/voice/index.js +26 -0
- package/dist/knowledge/graph-rag.d.ts +125 -0
- package/dist/knowledge/graph-rag.js +289 -0
- package/dist/knowledge/index.d.ts +2 -0
- package/dist/knowledge/index.js +18 -0
- package/dist/knowledge/reranker.d.ts +86 -0
- package/dist/knowledge/reranker.js +196 -0
- package/dist/workflows/yaml-parser.d.ts +48 -0
- package/dist/workflows/yaml-parser.js +304 -0
- package/package.json +1 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pinecone Vector Store Integration
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PineconeVectorStore = void 0;
|
|
7
|
+
exports.createPineconeStore = createPineconeStore;
|
|
8
|
+
const base_1 = require("./base");
|
|
9
|
+
class PineconeVectorStore extends base_1.BaseVectorStore {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super({ id: config.id || 'pinecone', name: 'PineconeVectorStore' });
|
|
12
|
+
this.indexHosts = new Map();
|
|
13
|
+
this.apiKey = config.apiKey;
|
|
14
|
+
this.baseUrl = 'https://api.pinecone.io';
|
|
15
|
+
}
|
|
16
|
+
async request(path, options = {}) {
|
|
17
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
18
|
+
...options,
|
|
19
|
+
headers: {
|
|
20
|
+
'Api-Key': this.apiKey,
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
...options.headers
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
const error = await response.text();
|
|
27
|
+
throw new Error(`Pinecone API error: ${response.status} - ${error}`);
|
|
28
|
+
}
|
|
29
|
+
const text = await response.text();
|
|
30
|
+
return text ? JSON.parse(text) : {};
|
|
31
|
+
}
|
|
32
|
+
async indexRequest(indexName, path, options = {}) {
|
|
33
|
+
let host = this.indexHosts.get(indexName);
|
|
34
|
+
if (!host) {
|
|
35
|
+
const info = await this.request(`/indexes/${indexName}`);
|
|
36
|
+
host = info.host;
|
|
37
|
+
this.indexHosts.set(indexName, host);
|
|
38
|
+
}
|
|
39
|
+
const response = await fetch(`https://${host}${path}`, {
|
|
40
|
+
...options,
|
|
41
|
+
headers: {
|
|
42
|
+
'Api-Key': this.apiKey,
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
...options.headers
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
const error = await response.text();
|
|
49
|
+
throw new Error(`Pinecone Index API error: ${response.status} - ${error}`);
|
|
50
|
+
}
|
|
51
|
+
const text = await response.text();
|
|
52
|
+
return text ? JSON.parse(text) : {};
|
|
53
|
+
}
|
|
54
|
+
async createIndex(params) {
|
|
55
|
+
const metricMap = {
|
|
56
|
+
cosine: 'cosine',
|
|
57
|
+
euclidean: 'euclidean',
|
|
58
|
+
dotProduct: 'dotproduct'
|
|
59
|
+
};
|
|
60
|
+
await this.request('/indexes', {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
name: params.indexName,
|
|
64
|
+
dimension: params.dimension,
|
|
65
|
+
metric: metricMap[params.metric || 'cosine'],
|
|
66
|
+
spec: {
|
|
67
|
+
serverless: {
|
|
68
|
+
cloud: 'aws',
|
|
69
|
+
region: 'us-east-1'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
// Wait for index to be ready
|
|
75
|
+
let ready = false;
|
|
76
|
+
let attempts = 0;
|
|
77
|
+
while (!ready && attempts < 60) {
|
|
78
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
79
|
+
try {
|
|
80
|
+
const info = await this.request(`/indexes/${params.indexName}`);
|
|
81
|
+
ready = info.status?.ready === true;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Index not ready yet
|
|
85
|
+
}
|
|
86
|
+
attempts++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async listIndexes() {
|
|
90
|
+
const response = await this.request('/indexes');
|
|
91
|
+
return (response.indexes || []).map((idx) => idx.name);
|
|
92
|
+
}
|
|
93
|
+
async describeIndex(indexName) {
|
|
94
|
+
const info = await this.request(`/indexes/${indexName}`);
|
|
95
|
+
const stats = await this.indexRequest(indexName, '/describe_index_stats', { method: 'POST', body: '{}' });
|
|
96
|
+
const metricMap = {
|
|
97
|
+
cosine: 'cosine',
|
|
98
|
+
euclidean: 'euclidean',
|
|
99
|
+
dotproduct: 'dotProduct'
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
dimension: info.dimension,
|
|
103
|
+
count: stats.totalVectorCount || 0,
|
|
104
|
+
metric: metricMap[info.metric] || 'cosine'
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async deleteIndex(indexName) {
|
|
108
|
+
await this.request(`/indexes/${indexName}`, { method: 'DELETE' });
|
|
109
|
+
this.indexHosts.delete(indexName);
|
|
110
|
+
}
|
|
111
|
+
async upsert(params) {
|
|
112
|
+
const vectors = params.vectors.map(v => ({
|
|
113
|
+
id: v.id,
|
|
114
|
+
values: v.vector,
|
|
115
|
+
metadata: v.metadata
|
|
116
|
+
}));
|
|
117
|
+
// Batch upsert in chunks of 100
|
|
118
|
+
const batchSize = 100;
|
|
119
|
+
const ids = [];
|
|
120
|
+
for (let i = 0; i < vectors.length; i += batchSize) {
|
|
121
|
+
const batch = vectors.slice(i, i + batchSize);
|
|
122
|
+
await this.indexRequest(params.indexName, '/vectors/upsert', {
|
|
123
|
+
method: 'POST',
|
|
124
|
+
body: JSON.stringify({ vectors: batch })
|
|
125
|
+
});
|
|
126
|
+
ids.push(...batch.map(v => v.id));
|
|
127
|
+
}
|
|
128
|
+
return ids;
|
|
129
|
+
}
|
|
130
|
+
async query(params) {
|
|
131
|
+
const response = await this.indexRequest(params.indexName, '/query', {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
body: JSON.stringify({
|
|
134
|
+
vector: params.vector,
|
|
135
|
+
topK: params.topK || 10,
|
|
136
|
+
filter: params.filter,
|
|
137
|
+
includeMetadata: params.includeMetadata !== false,
|
|
138
|
+
includeValues: params.includeVectors
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
return (response.matches || []).map((match) => ({
|
|
142
|
+
id: match.id,
|
|
143
|
+
score: match.score,
|
|
144
|
+
metadata: match.metadata,
|
|
145
|
+
vector: match.values
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
async delete(params) {
|
|
149
|
+
if (params.ids) {
|
|
150
|
+
await this.indexRequest(params.indexName, '/vectors/delete', {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
body: JSON.stringify({ ids: params.ids })
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else if (params.filter) {
|
|
156
|
+
await this.indexRequest(params.indexName, '/vectors/delete', {
|
|
157
|
+
method: 'POST',
|
|
158
|
+
body: JSON.stringify({ filter: params.filter })
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async update(indexName, id, metadata) {
|
|
163
|
+
await this.indexRequest(indexName, '/vectors/update', {
|
|
164
|
+
method: 'POST',
|
|
165
|
+
body: JSON.stringify({ id, setMetadata: metadata })
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.PineconeVectorStore = PineconeVectorStore;
|
|
170
|
+
function createPineconeStore(config) {
|
|
171
|
+
return new PineconeVectorStore(config);
|
|
172
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Qdrant Vector Store Integration
|
|
3
|
+
*/
|
|
4
|
+
import { BaseVectorStore, CreateIndexParams, UpsertParams, QueryParams, DeleteParams, QueryResult, IndexStats } from './base';
|
|
5
|
+
export interface QdrantConfig {
|
|
6
|
+
url: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class QdrantVectorStore extends BaseVectorStore {
|
|
10
|
+
private url;
|
|
11
|
+
private apiKey?;
|
|
12
|
+
constructor(config: QdrantConfig & {
|
|
13
|
+
id?: string;
|
|
14
|
+
});
|
|
15
|
+
private request;
|
|
16
|
+
createIndex(params: CreateIndexParams): Promise<void>;
|
|
17
|
+
listIndexes(): Promise<string[]>;
|
|
18
|
+
describeIndex(indexName: string): Promise<IndexStats>;
|
|
19
|
+
deleteIndex(indexName: string): Promise<void>;
|
|
20
|
+
upsert(params: UpsertParams): Promise<string[]>;
|
|
21
|
+
query(params: QueryParams): Promise<QueryResult[]>;
|
|
22
|
+
delete(params: DeleteParams): Promise<void>;
|
|
23
|
+
update(indexName: string, id: string, metadata: Record<string, any>): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createQdrantStore(config: QdrantConfig): QdrantVectorStore;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Qdrant Vector Store Integration
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.QdrantVectorStore = void 0;
|
|
7
|
+
exports.createQdrantStore = createQdrantStore;
|
|
8
|
+
const base_1 = require("./base");
|
|
9
|
+
class QdrantVectorStore extends base_1.BaseVectorStore {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super({ id: config.id || 'qdrant', name: 'QdrantVectorStore' });
|
|
12
|
+
this.url = config.url.replace(/\/$/, '');
|
|
13
|
+
this.apiKey = config.apiKey;
|
|
14
|
+
}
|
|
15
|
+
async request(path, options = {}) {
|
|
16
|
+
const headers = {
|
|
17
|
+
'Content-Type': 'application/json'
|
|
18
|
+
};
|
|
19
|
+
if (this.apiKey) {
|
|
20
|
+
headers['api-key'] = this.apiKey;
|
|
21
|
+
}
|
|
22
|
+
const response = await fetch(`${this.url}${path}`, {
|
|
23
|
+
...options,
|
|
24
|
+
headers: { ...headers, ...options.headers }
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
const error = await response.text();
|
|
28
|
+
throw new Error(`Qdrant API error: ${response.status} - ${error}`);
|
|
29
|
+
}
|
|
30
|
+
const text = await response.text();
|
|
31
|
+
return text ? JSON.parse(text) : {};
|
|
32
|
+
}
|
|
33
|
+
async createIndex(params) {
|
|
34
|
+
const distanceMap = {
|
|
35
|
+
cosine: 'Cosine',
|
|
36
|
+
euclidean: 'Euclid',
|
|
37
|
+
dotProduct: 'Dot'
|
|
38
|
+
};
|
|
39
|
+
await this.request(`/collections/${params.indexName}`, {
|
|
40
|
+
method: 'PUT',
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
vectors: {
|
|
43
|
+
size: params.dimension,
|
|
44
|
+
distance: distanceMap[params.metric || 'cosine']
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async listIndexes() {
|
|
50
|
+
const response = await this.request('/collections');
|
|
51
|
+
return (response.result?.collections || []).map((c) => c.name);
|
|
52
|
+
}
|
|
53
|
+
async describeIndex(indexName) {
|
|
54
|
+
const response = await this.request(`/collections/${indexName}`);
|
|
55
|
+
const config = response.result?.config?.params?.vectors;
|
|
56
|
+
const distanceMap = {
|
|
57
|
+
'Cosine': 'cosine',
|
|
58
|
+
'Euclid': 'euclidean',
|
|
59
|
+
'Dot': 'dotProduct'
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
dimension: config?.size || 0,
|
|
63
|
+
count: response.result?.points_count || 0,
|
|
64
|
+
metric: distanceMap[config?.distance] || 'cosine'
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async deleteIndex(indexName) {
|
|
68
|
+
await this.request(`/collections/${indexName}`, { method: 'DELETE' });
|
|
69
|
+
}
|
|
70
|
+
async upsert(params) {
|
|
71
|
+
const points = params.vectors.map(v => ({
|
|
72
|
+
id: v.id,
|
|
73
|
+
vector: v.vector,
|
|
74
|
+
payload: {
|
|
75
|
+
...v.metadata,
|
|
76
|
+
_content: v.content
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
await this.request(`/collections/${params.indexName}/points`, {
|
|
80
|
+
method: 'PUT',
|
|
81
|
+
body: JSON.stringify({ points })
|
|
82
|
+
});
|
|
83
|
+
return params.vectors.map(v => v.id);
|
|
84
|
+
}
|
|
85
|
+
async query(params) {
|
|
86
|
+
let filter = undefined;
|
|
87
|
+
if (params.filter) {
|
|
88
|
+
filter = {
|
|
89
|
+
must: Object.entries(params.filter).map(([key, value]) => ({
|
|
90
|
+
key,
|
|
91
|
+
match: { value }
|
|
92
|
+
}))
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const response = await this.request(`/collections/${params.indexName}/points/search`, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
body: JSON.stringify({
|
|
98
|
+
vector: params.vector,
|
|
99
|
+
limit: params.topK || 10,
|
|
100
|
+
filter,
|
|
101
|
+
with_payload: params.includeMetadata !== false,
|
|
102
|
+
with_vector: params.includeVectors
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
return (response.result || []).map((r) => ({
|
|
106
|
+
id: r.id,
|
|
107
|
+
score: r.score,
|
|
108
|
+
metadata: r.payload ? { ...r.payload, _content: undefined } : undefined,
|
|
109
|
+
content: r.payload?._content,
|
|
110
|
+
vector: r.vector
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
async delete(params) {
|
|
114
|
+
if (params.ids) {
|
|
115
|
+
await this.request(`/collections/${params.indexName}/points/delete`, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
body: JSON.stringify({ points: params.ids })
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else if (params.filter) {
|
|
121
|
+
const filter = {
|
|
122
|
+
must: Object.entries(params.filter).map(([key, value]) => ({
|
|
123
|
+
key,
|
|
124
|
+
match: { value }
|
|
125
|
+
}))
|
|
126
|
+
};
|
|
127
|
+
await this.request(`/collections/${params.indexName}/points/delete`, {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
body: JSON.stringify({ filter })
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async update(indexName, id, metadata) {
|
|
134
|
+
await this.request(`/collections/${indexName}/points/payload`, {
|
|
135
|
+
method: 'POST',
|
|
136
|
+
body: JSON.stringify({
|
|
137
|
+
points: [id],
|
|
138
|
+
payload: metadata
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.QdrantVectorStore = QdrantVectorStore;
|
|
144
|
+
function createQdrantStore(config) {
|
|
145
|
+
return new QdrantVectorStore(config);
|
|
146
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weaviate Vector Store Integration
|
|
3
|
+
*/
|
|
4
|
+
import { BaseVectorStore, CreateIndexParams, UpsertParams, QueryParams, DeleteParams, QueryResult, IndexStats } from './base';
|
|
5
|
+
export interface WeaviateConfig {
|
|
6
|
+
host: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
scheme?: 'http' | 'https';
|
|
9
|
+
}
|
|
10
|
+
export declare class WeaviateVectorStore extends BaseVectorStore {
|
|
11
|
+
private host;
|
|
12
|
+
private apiKey?;
|
|
13
|
+
private scheme;
|
|
14
|
+
constructor(config: WeaviateConfig & {
|
|
15
|
+
id?: string;
|
|
16
|
+
});
|
|
17
|
+
private get baseUrl();
|
|
18
|
+
private request;
|
|
19
|
+
private graphql;
|
|
20
|
+
private toClassName;
|
|
21
|
+
createIndex(params: CreateIndexParams): Promise<void>;
|
|
22
|
+
listIndexes(): Promise<string[]>;
|
|
23
|
+
describeIndex(indexName: string): Promise<IndexStats>;
|
|
24
|
+
deleteIndex(indexName: string): Promise<void>;
|
|
25
|
+
upsert(params: UpsertParams): Promise<string[]>;
|
|
26
|
+
query(params: QueryParams): Promise<QueryResult[]>;
|
|
27
|
+
delete(params: DeleteParams): Promise<void>;
|
|
28
|
+
update(indexName: string, id: string, metadata: Record<string, any>): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare function createWeaviateStore(config: WeaviateConfig): WeaviateVectorStore;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Weaviate Vector Store Integration
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WeaviateVectorStore = void 0;
|
|
7
|
+
exports.createWeaviateStore = createWeaviateStore;
|
|
8
|
+
const base_1 = require("./base");
|
|
9
|
+
class WeaviateVectorStore extends base_1.BaseVectorStore {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super({ id: config.id || 'weaviate', name: 'WeaviateVectorStore' });
|
|
12
|
+
this.host = config.host;
|
|
13
|
+
this.apiKey = config.apiKey;
|
|
14
|
+
this.scheme = config.scheme || 'https';
|
|
15
|
+
}
|
|
16
|
+
get baseUrl() {
|
|
17
|
+
return `${this.scheme}://${this.host}`;
|
|
18
|
+
}
|
|
19
|
+
async request(path, options = {}) {
|
|
20
|
+
const headers = {
|
|
21
|
+
'Content-Type': 'application/json'
|
|
22
|
+
};
|
|
23
|
+
if (this.apiKey) {
|
|
24
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
25
|
+
}
|
|
26
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
27
|
+
...options,
|
|
28
|
+
headers: { ...headers, ...options.headers }
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
const error = await response.text();
|
|
32
|
+
throw new Error(`Weaviate API error: ${response.status} - ${error}`);
|
|
33
|
+
}
|
|
34
|
+
const text = await response.text();
|
|
35
|
+
return text ? JSON.parse(text) : {};
|
|
36
|
+
}
|
|
37
|
+
async graphql(query, variables) {
|
|
38
|
+
const response = await this.request('/v1/graphql', {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
body: JSON.stringify({ query, variables })
|
|
41
|
+
});
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
toClassName(indexName) {
|
|
45
|
+
// Weaviate class names must start with uppercase
|
|
46
|
+
return indexName.charAt(0).toUpperCase() + indexName.slice(1);
|
|
47
|
+
}
|
|
48
|
+
async createIndex(params) {
|
|
49
|
+
const className = this.toClassName(params.indexName);
|
|
50
|
+
const vectorIndexConfig = {
|
|
51
|
+
distance: params.metric === 'euclidean' ? 'l2-squared' :
|
|
52
|
+
params.metric === 'dotProduct' ? 'dot' : 'cosine'
|
|
53
|
+
};
|
|
54
|
+
await this.request('/v1/schema', {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
body: JSON.stringify({
|
|
57
|
+
class: className,
|
|
58
|
+
vectorIndexConfig,
|
|
59
|
+
properties: [
|
|
60
|
+
{
|
|
61
|
+
name: 'content',
|
|
62
|
+
dataType: ['text']
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'metadata',
|
|
66
|
+
dataType: ['object']
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async listIndexes() {
|
|
73
|
+
const response = await this.request('/v1/schema');
|
|
74
|
+
return (response.classes || []).map((c) => c.class.toLowerCase());
|
|
75
|
+
}
|
|
76
|
+
async describeIndex(indexName) {
|
|
77
|
+
const className = this.toClassName(indexName);
|
|
78
|
+
const response = await this.request(`/v1/schema/${className}`);
|
|
79
|
+
// Get count via aggregate
|
|
80
|
+
const countQuery = `{
|
|
81
|
+
Aggregate {
|
|
82
|
+
${className} {
|
|
83
|
+
meta { count }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}`;
|
|
87
|
+
const countResponse = await this.graphql(countQuery);
|
|
88
|
+
const count = countResponse.data?.Aggregate?.[className]?.[0]?.meta?.count || 0;
|
|
89
|
+
const distanceMap = {
|
|
90
|
+
'cosine': 'cosine',
|
|
91
|
+
'l2-squared': 'euclidean',
|
|
92
|
+
'dot': 'dotProduct'
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
dimension: response.vectorIndexConfig?.dimensions || 0,
|
|
96
|
+
count,
|
|
97
|
+
metric: distanceMap[response.vectorIndexConfig?.distance] || 'cosine'
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async deleteIndex(indexName) {
|
|
101
|
+
const className = this.toClassName(indexName);
|
|
102
|
+
await this.request(`/v1/schema/${className}`, { method: 'DELETE' });
|
|
103
|
+
}
|
|
104
|
+
async upsert(params) {
|
|
105
|
+
const className = this.toClassName(params.indexName);
|
|
106
|
+
const ids = [];
|
|
107
|
+
// Batch upsert
|
|
108
|
+
const objects = params.vectors.map(v => ({
|
|
109
|
+
class: className,
|
|
110
|
+
id: v.id,
|
|
111
|
+
vector: v.vector,
|
|
112
|
+
properties: {
|
|
113
|
+
content: v.content || '',
|
|
114
|
+
metadata: v.metadata || {}
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
// Batch in chunks of 100
|
|
118
|
+
const batchSize = 100;
|
|
119
|
+
for (let i = 0; i < objects.length; i += batchSize) {
|
|
120
|
+
const batch = objects.slice(i, i + batchSize);
|
|
121
|
+
await this.request('/v1/batch/objects', {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
body: JSON.stringify({ objects: batch })
|
|
124
|
+
});
|
|
125
|
+
ids.push(...batch.map(o => o.id));
|
|
126
|
+
}
|
|
127
|
+
return ids;
|
|
128
|
+
}
|
|
129
|
+
async query(params) {
|
|
130
|
+
const className = this.toClassName(params.indexName);
|
|
131
|
+
const topK = params.topK || 10;
|
|
132
|
+
let whereClause = '';
|
|
133
|
+
if (params.filter) {
|
|
134
|
+
const conditions = Object.entries(params.filter).map(([key, value]) => {
|
|
135
|
+
return `{ path: ["metadata", "${key}"], operator: Equal, valueString: "${value}" }`;
|
|
136
|
+
});
|
|
137
|
+
if (conditions.length > 0) {
|
|
138
|
+
whereClause = `where: { operator: And, operands: [${conditions.join(', ')}] }`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const query = `{
|
|
142
|
+
Get {
|
|
143
|
+
${className}(
|
|
144
|
+
nearVector: { vector: [${params.vector.join(',')}] }
|
|
145
|
+
limit: ${topK}
|
|
146
|
+
${whereClause}
|
|
147
|
+
) {
|
|
148
|
+
_additional {
|
|
149
|
+
id
|
|
150
|
+
distance
|
|
151
|
+
${params.includeVectors ? 'vector' : ''}
|
|
152
|
+
}
|
|
153
|
+
content
|
|
154
|
+
metadata
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}`;
|
|
158
|
+
const response = await this.graphql(query);
|
|
159
|
+
const results = response.data?.Get?.[className] || [];
|
|
160
|
+
return results.map((r) => ({
|
|
161
|
+
id: r._additional.id,
|
|
162
|
+
score: 1 - (r._additional.distance || 0), // Convert distance to similarity
|
|
163
|
+
metadata: r.metadata,
|
|
164
|
+
content: r.content,
|
|
165
|
+
vector: r._additional.vector
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
async delete(params) {
|
|
169
|
+
const className = this.toClassName(params.indexName);
|
|
170
|
+
if (params.ids) {
|
|
171
|
+
for (const id of params.ids) {
|
|
172
|
+
await this.request(`/v1/objects/${className}/${id}`, { method: 'DELETE' });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if (params.filter) {
|
|
176
|
+
// Delete by filter using batch delete
|
|
177
|
+
const conditions = Object.entries(params.filter).map(([key, value]) => ({
|
|
178
|
+
path: ['metadata', key],
|
|
179
|
+
operator: 'Equal',
|
|
180
|
+
valueString: String(value)
|
|
181
|
+
}));
|
|
182
|
+
await this.request('/v1/batch/objects', {
|
|
183
|
+
method: 'DELETE',
|
|
184
|
+
body: JSON.stringify({
|
|
185
|
+
match: {
|
|
186
|
+
class: className,
|
|
187
|
+
where: { operator: 'And', operands: conditions }
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async update(indexName, id, metadata) {
|
|
194
|
+
const className = this.toClassName(indexName);
|
|
195
|
+
await this.request(`/v1/objects/${className}/${id}`, {
|
|
196
|
+
method: 'PATCH',
|
|
197
|
+
body: JSON.stringify({
|
|
198
|
+
properties: { metadata }
|
|
199
|
+
})
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.WeaviateVectorStore = WeaviateVectorStore;
|
|
204
|
+
function createWeaviateStore(config) {
|
|
205
|
+
return new WeaviateVectorStore(config);
|
|
206
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Voice - Abstract class for voice/TTS integrations
|
|
3
|
+
* Matches mastra's MastraVoice pattern
|
|
4
|
+
*/
|
|
5
|
+
export interface VoiceConfig {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
model?: string;
|
|
8
|
+
voice?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SpeakOptions {
|
|
11
|
+
voice?: string;
|
|
12
|
+
speed?: number;
|
|
13
|
+
pitch?: number;
|
|
14
|
+
format?: 'mp3' | 'wav' | 'ogg' | 'opus';
|
|
15
|
+
}
|
|
16
|
+
export interface ListenOptions {
|
|
17
|
+
language?: string;
|
|
18
|
+
model?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Speaker {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
language?: string;
|
|
24
|
+
gender?: 'male' | 'female' | 'neutral';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Abstract base class for voice providers
|
|
28
|
+
*/
|
|
29
|
+
export declare abstract class BaseVoiceProvider {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
protected apiKey?: string;
|
|
32
|
+
protected defaultVoice?: string;
|
|
33
|
+
constructor(config: VoiceConfig & {
|
|
34
|
+
name?: string;
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Convert text to speech
|
|
38
|
+
*/
|
|
39
|
+
abstract speak(text: string, options?: SpeakOptions): Promise<Buffer | ReadableStream>;
|
|
40
|
+
/**
|
|
41
|
+
* Convert speech to text
|
|
42
|
+
*/
|
|
43
|
+
abstract listen(audio: Buffer | ReadableStream, options?: ListenOptions): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Get available voices/speakers
|
|
46
|
+
*/
|
|
47
|
+
abstract getSpeakers(): Promise<Speaker[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Check if provider is available
|
|
50
|
+
*/
|
|
51
|
+
abstract isAvailable(): Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* OpenAI Voice Provider (TTS and Whisper)
|
|
55
|
+
*/
|
|
56
|
+
export declare class OpenAIVoiceProvider extends BaseVoiceProvider {
|
|
57
|
+
private baseUrl;
|
|
58
|
+
constructor(config?: VoiceConfig);
|
|
59
|
+
speak(text: string, options?: SpeakOptions): Promise<Buffer>;
|
|
60
|
+
listen(audio: Buffer | ReadableStream, options?: ListenOptions): Promise<string>;
|
|
61
|
+
getSpeakers(): Promise<Speaker[]>;
|
|
62
|
+
isAvailable(): Promise<boolean>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* ElevenLabs Voice Provider
|
|
66
|
+
*/
|
|
67
|
+
export declare class ElevenLabsVoiceProvider extends BaseVoiceProvider {
|
|
68
|
+
private baseUrl;
|
|
69
|
+
constructor(config?: VoiceConfig);
|
|
70
|
+
speak(text: string, options?: SpeakOptions): Promise<Buffer>;
|
|
71
|
+
listen(_audio: Buffer | ReadableStream, _options?: ListenOptions): Promise<string>;
|
|
72
|
+
getSpeakers(): Promise<Speaker[]>;
|
|
73
|
+
isAvailable(): Promise<boolean>;
|
|
74
|
+
}
|
|
75
|
+
export declare function createOpenAIVoice(config?: VoiceConfig): OpenAIVoiceProvider;
|
|
76
|
+
export declare function createElevenLabsVoice(config?: VoiceConfig): ElevenLabsVoiceProvider;
|