@vectorstores/weaviate 0.1.4 → 0.1.6

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 CHANGED
@@ -73,8 +73,8 @@ const NODE_SCHEMA = [
73
73
  }
74
74
  ];
75
75
  const SIMILARITY_KEYS = {
76
- [core.VectorStoreQueryMode.DEFAULT]: "distance",
77
- [core.VectorStoreQueryMode.HYBRID]: "score"
76
+ default: "distance",
77
+ hybrid: "score"
78
78
  };
79
79
  const buildFilterItem = (collection, filter)=>{
80
80
  const { key, operator, value } = filter;
@@ -192,27 +192,41 @@ class WeaviateVectorStore extends core.BaseVectorStore {
192
192
  if (query.filters) {
193
193
  filters = toWeaviateFilter(collection, query.filters);
194
194
  }
195
- const hybridOptions = {
196
- returnMetadata: Object.values(SIMILARITY_KEYS),
197
- returnProperties: allProperties,
198
- includeVector: true
199
- };
200
- const alpha = this.getQueryAlpha(query);
201
- if (query.queryEmbedding) {
202
- hybridOptions.vector = query.queryEmbedding;
203
- }
204
- if (query.similarityTopK) {
205
- hybridOptions.limit = query.similarityTopK;
206
- }
207
- if (alpha) {
208
- hybridOptions.alpha = alpha;
209
- }
210
- if (filters) {
211
- hybridOptions.filters = filters;
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 === core.VectorStoreQueryMode.DEFAULT) return 1;
269
- if (query.mode === core.VectorStoreQueryMode.HYBRID && query.queryStr) return query.alpha;
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
@@ -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
@@ -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;
@@ -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 { VectorStoreQueryMode, BaseVectorStore, nodeToMetadata, MetadataMode, metadataDictToNode, parseArrayValue, parseNumberValue } from '@vectorstores/core';
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
- [VectorStoreQueryMode.DEFAULT]: "distance",
71
- [VectorStoreQueryMode.HYBRID]: "score"
70
+ default: "distance",
71
+ hybrid: "score"
72
72
  };
73
73
  const buildFilterItem = (collection, filter)=>{
74
74
  const { key, operator, value } = filter;
@@ -186,27 +186,41 @@ class WeaviateVectorStore extends BaseVectorStore {
186
186
  if (query.filters) {
187
187
  filters = toWeaviateFilter(collection, query.filters);
188
188
  }
189
- const hybridOptions = {
190
- returnMetadata: Object.values(SIMILARITY_KEYS),
191
- returnProperties: allProperties,
192
- includeVector: true
193
- };
194
- const alpha = this.getQueryAlpha(query);
195
- if (query.queryEmbedding) {
196
- hybridOptions.vector = query.queryEmbedding;
197
- }
198
- if (query.similarityTopK) {
199
- hybridOptions.limit = query.similarityTopK;
200
- }
201
- if (alpha) {
202
- hybridOptions.alpha = alpha;
203
- }
204
- if (filters) {
205
- hybridOptions.filters = filters;
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 === VectorStoreQueryMode.DEFAULT) return 1;
263
- if (query.mode === VectorStoreQueryMode.HYBRID && query.queryStr) return query.alpha;
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 { VectorStoreQueryMode, BaseVectorStore, nodeToMetadata, MetadataMode, metadataDictToNode, parseArrayValue, parseNumberValue } from '@vectorstores/core';
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
- [VectorStoreQueryMode.DEFAULT]: "distance",
71
- [VectorStoreQueryMode.HYBRID]: "score"
70
+ default: "distance",
71
+ hybrid: "score"
72
72
  };
73
73
  const buildFilterItem = (collection, filter)=>{
74
74
  const { key, operator, value } = filter;
@@ -186,27 +186,41 @@ class WeaviateVectorStore extends BaseVectorStore {
186
186
  if (query.filters) {
187
187
  filters = toWeaviateFilter(collection, query.filters);
188
188
  }
189
- const hybridOptions = {
190
- returnMetadata: Object.values(SIMILARITY_KEYS),
191
- returnProperties: allProperties,
192
- includeVector: true
193
- };
194
- const alpha = this.getQueryAlpha(query);
195
- if (query.queryEmbedding) {
196
- hybridOptions.vector = query.queryEmbedding;
197
- }
198
- if (query.similarityTopK) {
199
- hybridOptions.limit = query.similarityTopK;
200
- }
201
- if (alpha) {
202
- hybridOptions.alpha = alpha;
203
- }
204
- if (filters) {
205
- hybridOptions.filters = filters;
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 === VectorStoreQueryMode.DEFAULT) return 1;
263
- if (query.mode === VectorStoreQueryMode.HYBRID && query.queryStr) return query.alpha;
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",
4
+ "version": "0.1.6",
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.4",
38
+ "@vectorstores/core": "0.1.6",
39
39
  "@vectorstores/env": "0.1.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@vectorstores/core": "0.1.4",
42
+ "@vectorstores/core": "0.1.6",
43
43
  "@vectorstores/env": "0.1.0"
44
44
  },
45
45
  "dependencies": {