@vectorstores/weaviate 0.1.5 → 0.1.7
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/index.cjs +38 -24
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.edge-light.d.ts +3 -5
- package/dist/index.edge-light.js +39 -25
- package/dist/index.js +39 -25
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -73,8 +73,8 @@ const NODE_SCHEMA = [
|
|
|
73
73
|
}
|
|
74
74
|
];
|
|
75
75
|
const SIMILARITY_KEYS = {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
default: "distance",
|
|
77
|
+
hybrid: "score"
|
|
78
78
|
};
|
|
79
79
|
const buildFilterItem = (collection, filter)=>{
|
|
80
80
|
const { key, operator, value } = filter;
|
|
@@ -126,7 +126,7 @@ const toWeaviateFilter = (collection, standardFilters)=>{
|
|
|
126
126
|
};
|
|
127
127
|
class WeaviateVectorStore extends core.BaseVectorStore {
|
|
128
128
|
constructor(init){
|
|
129
|
-
super(
|
|
129
|
+
super(), this.storesText = true, this.flatMetadata = true, this.sanitizeMetadata = true;
|
|
130
130
|
if (init?.weaviateClient) {
|
|
131
131
|
// Use the provided client
|
|
132
132
|
this.weaviateClient = init.weaviateClient;
|
|
@@ -192,27 +192,41 @@ class WeaviateVectorStore extends core.BaseVectorStore {
|
|
|
192
192
|
if (query.filters) {
|
|
193
193
|
filters = toWeaviateFilter(collection, query.filters);
|
|
194
194
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
hybridOptions
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
195
|
+
let queryResult;
|
|
196
|
+
if (query.mode === "bm25") {
|
|
197
|
+
if (!query.queryStr) {
|
|
198
|
+
throw new Error("queryStr is required for BM25 mode");
|
|
199
|
+
}
|
|
200
|
+
queryResult = await collection.query.bm25(query.queryStr, {
|
|
201
|
+
limit: query.similarityTopK,
|
|
202
|
+
...filters && {
|
|
203
|
+
filters
|
|
204
|
+
},
|
|
205
|
+
returnProperties: allProperties
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
const hybridOptions = {
|
|
209
|
+
returnMetadata: Object.values(SIMILARITY_KEYS),
|
|
210
|
+
returnProperties: allProperties,
|
|
211
|
+
includeVector: true
|
|
212
|
+
};
|
|
213
|
+
const alpha = this.getQueryAlpha(query);
|
|
214
|
+
if (query.queryEmbedding) {
|
|
215
|
+
hybridOptions.vector = query.queryEmbedding;
|
|
216
|
+
}
|
|
217
|
+
if (query.similarityTopK) {
|
|
218
|
+
hybridOptions.limit = query.similarityTopK;
|
|
219
|
+
}
|
|
220
|
+
if (alpha !== undefined) {
|
|
221
|
+
hybridOptions.alpha = alpha;
|
|
222
|
+
}
|
|
223
|
+
if (filters) {
|
|
224
|
+
hybridOptions.filters = filters;
|
|
225
|
+
}
|
|
226
|
+
queryResult = await collection.query.hybrid(query.queryStr ?? "", hybridOptions);
|
|
212
227
|
}
|
|
213
|
-
const queryResult = await collection.query.hybrid(query.queryStr, hybridOptions);
|
|
214
228
|
const entries = queryResult.objects;
|
|
215
|
-
const similarityKey = SIMILARITY_KEYS[query.mode];
|
|
229
|
+
const similarityKey = SIMILARITY_KEYS[query.mode] ?? "distance";
|
|
216
230
|
const nodes = [];
|
|
217
231
|
const similarities = [];
|
|
218
232
|
const ids = [];
|
|
@@ -265,8 +279,8 @@ class WeaviateVectorStore extends core.BaseVectorStore {
|
|
|
265
279
|
}
|
|
266
280
|
getQueryAlpha(query) {
|
|
267
281
|
if (!query.queryEmbedding) return undefined;
|
|
268
|
-
if (query.mode ===
|
|
269
|
-
if (query.mode ===
|
|
282
|
+
if (query.mode === "default") return 1;
|
|
283
|
+
if (query.mode === "hybrid" && query.queryStr) return query.alpha;
|
|
270
284
|
return undefined;
|
|
271
285
|
}
|
|
272
286
|
async getAllProperties() {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseVectorStore,
|
|
1
|
+
import { BaseVectorStore, BaseNode, Metadata, VectorStoreQuery, VectorStoreQueryResult } from '@vectorstores/core';
|
|
2
2
|
import { WeaviateClient, DeleteManyOptions } from 'weaviate-client';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -21,7 +21,7 @@ declare class WeaviateVectorStore extends BaseVectorStore {
|
|
|
21
21
|
private contentKey;
|
|
22
22
|
private embeddingKey;
|
|
23
23
|
private metadataKey;
|
|
24
|
-
constructor(init?:
|
|
24
|
+
constructor(init?: {
|
|
25
25
|
weaviateClient?: WeaviateClient;
|
|
26
26
|
cloudOptions?: {
|
|
27
27
|
clusterURL?: string;
|
|
@@ -37,9 +37,7 @@ declare class WeaviateVectorStore extends BaseVectorStore {
|
|
|
37
37
|
client(): Promise<WeaviateClient>;
|
|
38
38
|
add(nodes: BaseNode<Metadata>[]): Promise<string[]>;
|
|
39
39
|
delete(refDocId: string, deleteOptions?: DeleteManyOptions<boolean>): Promise<void>;
|
|
40
|
-
query(query: VectorStoreQuery
|
|
41
|
-
queryStr: string;
|
|
42
|
-
}): Promise<VectorStoreQueryResult>;
|
|
40
|
+
query(query: VectorStoreQuery): Promise<VectorStoreQueryResult>;
|
|
43
41
|
private getClient;
|
|
44
42
|
private ensureCollection;
|
|
45
43
|
private doesCollectionExist;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseVectorStore,
|
|
1
|
+
import { BaseVectorStore, BaseNode, Metadata, VectorStoreQuery, VectorStoreQueryResult } from '@vectorstores/core';
|
|
2
2
|
import { WeaviateClient, DeleteManyOptions } from 'weaviate-client';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -21,7 +21,7 @@ declare class WeaviateVectorStore extends BaseVectorStore {
|
|
|
21
21
|
private contentKey;
|
|
22
22
|
private embeddingKey;
|
|
23
23
|
private metadataKey;
|
|
24
|
-
constructor(init?:
|
|
24
|
+
constructor(init?: {
|
|
25
25
|
weaviateClient?: WeaviateClient;
|
|
26
26
|
cloudOptions?: {
|
|
27
27
|
clusterURL?: string;
|
|
@@ -37,9 +37,7 @@ declare class WeaviateVectorStore extends BaseVectorStore {
|
|
|
37
37
|
client(): Promise<WeaviateClient>;
|
|
38
38
|
add(nodes: BaseNode<Metadata>[]): Promise<string[]>;
|
|
39
39
|
delete(refDocId: string, deleteOptions?: DeleteManyOptions<boolean>): Promise<void>;
|
|
40
|
-
query(query: VectorStoreQuery
|
|
41
|
-
queryStr: string;
|
|
42
|
-
}): Promise<VectorStoreQueryResult>;
|
|
40
|
+
query(query: VectorStoreQuery): Promise<VectorStoreQueryResult>;
|
|
43
41
|
private getClient;
|
|
44
42
|
private ensureCollection;
|
|
45
43
|
private doesCollectionExist;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseVectorStore,
|
|
1
|
+
import { BaseVectorStore, BaseNode, Metadata, VectorStoreQuery, VectorStoreQueryResult } from '@vectorstores/core';
|
|
2
2
|
import { WeaviateClient, DeleteManyOptions } from 'weaviate-client';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -21,7 +21,7 @@ declare class WeaviateVectorStore extends BaseVectorStore {
|
|
|
21
21
|
private contentKey;
|
|
22
22
|
private embeddingKey;
|
|
23
23
|
private metadataKey;
|
|
24
|
-
constructor(init?:
|
|
24
|
+
constructor(init?: {
|
|
25
25
|
weaviateClient?: WeaviateClient;
|
|
26
26
|
cloudOptions?: {
|
|
27
27
|
clusterURL?: string;
|
|
@@ -37,9 +37,7 @@ declare class WeaviateVectorStore extends BaseVectorStore {
|
|
|
37
37
|
client(): Promise<WeaviateClient>;
|
|
38
38
|
add(nodes: BaseNode<Metadata>[]): Promise<string[]>;
|
|
39
39
|
delete(refDocId: string, deleteOptions?: DeleteManyOptions<boolean>): Promise<void>;
|
|
40
|
-
query(query: VectorStoreQuery
|
|
41
|
-
queryStr: string;
|
|
42
|
-
}): Promise<VectorStoreQueryResult>;
|
|
40
|
+
query(query: VectorStoreQuery): Promise<VectorStoreQueryResult>;
|
|
43
41
|
private getClient;
|
|
44
42
|
private ensureCollection;
|
|
45
43
|
private doesCollectionExist;
|
package/dist/index.edge-light.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseVectorStore, nodeToMetadata, MetadataMode, metadataDictToNode, parseArrayValue, parseNumberValue } from '@vectorstores/core';
|
|
2
2
|
import weaviate, { Filters } from 'weaviate-client';
|
|
3
3
|
import { getEnv } from '@vectorstores/env';
|
|
4
4
|
|
|
@@ -67,8 +67,8 @@ const NODE_SCHEMA = [
|
|
|
67
67
|
}
|
|
68
68
|
];
|
|
69
69
|
const SIMILARITY_KEYS = {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
default: "distance",
|
|
71
|
+
hybrid: "score"
|
|
72
72
|
};
|
|
73
73
|
const buildFilterItem = (collection, filter)=>{
|
|
74
74
|
const { key, operator, value } = filter;
|
|
@@ -120,7 +120,7 @@ const toWeaviateFilter = (collection, standardFilters)=>{
|
|
|
120
120
|
};
|
|
121
121
|
class WeaviateVectorStore extends BaseVectorStore {
|
|
122
122
|
constructor(init){
|
|
123
|
-
super(
|
|
123
|
+
super(), this.storesText = true, this.flatMetadata = true, this.sanitizeMetadata = true;
|
|
124
124
|
if (init?.weaviateClient) {
|
|
125
125
|
// Use the provided client
|
|
126
126
|
this.weaviateClient = init.weaviateClient;
|
|
@@ -186,27 +186,41 @@ class WeaviateVectorStore extends BaseVectorStore {
|
|
|
186
186
|
if (query.filters) {
|
|
187
187
|
filters = toWeaviateFilter(collection, query.filters);
|
|
188
188
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
hybridOptions
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
189
|
+
let queryResult;
|
|
190
|
+
if (query.mode === "bm25") {
|
|
191
|
+
if (!query.queryStr) {
|
|
192
|
+
throw new Error("queryStr is required for BM25 mode");
|
|
193
|
+
}
|
|
194
|
+
queryResult = await collection.query.bm25(query.queryStr, {
|
|
195
|
+
limit: query.similarityTopK,
|
|
196
|
+
...filters && {
|
|
197
|
+
filters
|
|
198
|
+
},
|
|
199
|
+
returnProperties: allProperties
|
|
200
|
+
});
|
|
201
|
+
} else {
|
|
202
|
+
const hybridOptions = {
|
|
203
|
+
returnMetadata: Object.values(SIMILARITY_KEYS),
|
|
204
|
+
returnProperties: allProperties,
|
|
205
|
+
includeVector: true
|
|
206
|
+
};
|
|
207
|
+
const alpha = this.getQueryAlpha(query);
|
|
208
|
+
if (query.queryEmbedding) {
|
|
209
|
+
hybridOptions.vector = query.queryEmbedding;
|
|
210
|
+
}
|
|
211
|
+
if (query.similarityTopK) {
|
|
212
|
+
hybridOptions.limit = query.similarityTopK;
|
|
213
|
+
}
|
|
214
|
+
if (alpha !== undefined) {
|
|
215
|
+
hybridOptions.alpha = alpha;
|
|
216
|
+
}
|
|
217
|
+
if (filters) {
|
|
218
|
+
hybridOptions.filters = filters;
|
|
219
|
+
}
|
|
220
|
+
queryResult = await collection.query.hybrid(query.queryStr ?? "", hybridOptions);
|
|
206
221
|
}
|
|
207
|
-
const queryResult = await collection.query.hybrid(query.queryStr, hybridOptions);
|
|
208
222
|
const entries = queryResult.objects;
|
|
209
|
-
const similarityKey = SIMILARITY_KEYS[query.mode];
|
|
223
|
+
const similarityKey = SIMILARITY_KEYS[query.mode] ?? "distance";
|
|
210
224
|
const nodes = [];
|
|
211
225
|
const similarities = [];
|
|
212
226
|
const ids = [];
|
|
@@ -259,8 +273,8 @@ class WeaviateVectorStore extends BaseVectorStore {
|
|
|
259
273
|
}
|
|
260
274
|
getQueryAlpha(query) {
|
|
261
275
|
if (!query.queryEmbedding) return undefined;
|
|
262
|
-
if (query.mode ===
|
|
263
|
-
if (query.mode ===
|
|
276
|
+
if (query.mode === "default") return 1;
|
|
277
|
+
if (query.mode === "hybrid" && query.queryStr) return query.alpha;
|
|
264
278
|
return undefined;
|
|
265
279
|
}
|
|
266
280
|
async getAllProperties() {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseVectorStore, nodeToMetadata, MetadataMode, metadataDictToNode, parseArrayValue, parseNumberValue } from '@vectorstores/core';
|
|
2
2
|
import weaviate, { Filters } from 'weaviate-client';
|
|
3
3
|
import { getEnv } from '@vectorstores/env';
|
|
4
4
|
|
|
@@ -67,8 +67,8 @@ const NODE_SCHEMA = [
|
|
|
67
67
|
}
|
|
68
68
|
];
|
|
69
69
|
const SIMILARITY_KEYS = {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
default: "distance",
|
|
71
|
+
hybrid: "score"
|
|
72
72
|
};
|
|
73
73
|
const buildFilterItem = (collection, filter)=>{
|
|
74
74
|
const { key, operator, value } = filter;
|
|
@@ -120,7 +120,7 @@ const toWeaviateFilter = (collection, standardFilters)=>{
|
|
|
120
120
|
};
|
|
121
121
|
class WeaviateVectorStore extends BaseVectorStore {
|
|
122
122
|
constructor(init){
|
|
123
|
-
super(
|
|
123
|
+
super(), this.storesText = true, this.flatMetadata = true, this.sanitizeMetadata = true;
|
|
124
124
|
if (init?.weaviateClient) {
|
|
125
125
|
// Use the provided client
|
|
126
126
|
this.weaviateClient = init.weaviateClient;
|
|
@@ -186,27 +186,41 @@ class WeaviateVectorStore extends BaseVectorStore {
|
|
|
186
186
|
if (query.filters) {
|
|
187
187
|
filters = toWeaviateFilter(collection, query.filters);
|
|
188
188
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
hybridOptions
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
189
|
+
let queryResult;
|
|
190
|
+
if (query.mode === "bm25") {
|
|
191
|
+
if (!query.queryStr) {
|
|
192
|
+
throw new Error("queryStr is required for BM25 mode");
|
|
193
|
+
}
|
|
194
|
+
queryResult = await collection.query.bm25(query.queryStr, {
|
|
195
|
+
limit: query.similarityTopK,
|
|
196
|
+
...filters && {
|
|
197
|
+
filters
|
|
198
|
+
},
|
|
199
|
+
returnProperties: allProperties
|
|
200
|
+
});
|
|
201
|
+
} else {
|
|
202
|
+
const hybridOptions = {
|
|
203
|
+
returnMetadata: Object.values(SIMILARITY_KEYS),
|
|
204
|
+
returnProperties: allProperties,
|
|
205
|
+
includeVector: true
|
|
206
|
+
};
|
|
207
|
+
const alpha = this.getQueryAlpha(query);
|
|
208
|
+
if (query.queryEmbedding) {
|
|
209
|
+
hybridOptions.vector = query.queryEmbedding;
|
|
210
|
+
}
|
|
211
|
+
if (query.similarityTopK) {
|
|
212
|
+
hybridOptions.limit = query.similarityTopK;
|
|
213
|
+
}
|
|
214
|
+
if (alpha !== undefined) {
|
|
215
|
+
hybridOptions.alpha = alpha;
|
|
216
|
+
}
|
|
217
|
+
if (filters) {
|
|
218
|
+
hybridOptions.filters = filters;
|
|
219
|
+
}
|
|
220
|
+
queryResult = await collection.query.hybrid(query.queryStr ?? "", hybridOptions);
|
|
206
221
|
}
|
|
207
|
-
const queryResult = await collection.query.hybrid(query.queryStr, hybridOptions);
|
|
208
222
|
const entries = queryResult.objects;
|
|
209
|
-
const similarityKey = SIMILARITY_KEYS[query.mode];
|
|
223
|
+
const similarityKey = SIMILARITY_KEYS[query.mode] ?? "distance";
|
|
210
224
|
const nodes = [];
|
|
211
225
|
const similarities = [];
|
|
212
226
|
const ids = [];
|
|
@@ -259,8 +273,8 @@ class WeaviateVectorStore extends BaseVectorStore {
|
|
|
259
273
|
}
|
|
260
274
|
getQueryAlpha(query) {
|
|
261
275
|
if (!query.queryEmbedding) return undefined;
|
|
262
|
-
if (query.mode ===
|
|
263
|
-
if (query.mode ===
|
|
276
|
+
if (query.mode === "default") return 1;
|
|
277
|
+
if (query.mode === "hybrid" && query.queryStr) return query.alpha;
|
|
264
278
|
return undefined;
|
|
265
279
|
}
|
|
266
280
|
async getAllProperties() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorstores/weaviate",
|
|
3
3
|
"description": "Weaviate Storage for vectorstores",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"vitest": "^3.2.0",
|
|
38
|
-
"@vectorstores/core": "0.1.
|
|
38
|
+
"@vectorstores/core": "0.1.7",
|
|
39
39
|
"@vectorstores/env": "0.1.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@vectorstores/core": "0.1.
|
|
42
|
+
"@vectorstores/core": "0.1.7",
|
|
43
43
|
"@vectorstores/env": "0.1.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|