@vectorstores/upstash 0.1.3 → 0.1.4

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
@@ -89,21 +89,31 @@ var env = require('@vectorstores/env');
89
89
  return results.every((result)=>result === "OK") ? "OK" : "NOT-OK";
90
90
  }
91
91
  /**
92
- * Deletes a single record from the database by id.
93
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
94
- * @param refDocId Unique identifier for the record to delete.
92
+ * Deletes all nodes from the database that belong to the given document.
93
+ * @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
95
94
  * @returns Promise that resolves if the delete query did not throw an error.
96
95
  */ async delete(refDocId) {
97
- await this.db.namespace(this.namespace).delete(refDocId);
96
+ // Query to find all node IDs with this ref_doc_id
97
+ const results = await this.db.query({
98
+ vector: new Array(1536).fill(0),
99
+ topK: 10000,
100
+ includeMetadata: true,
101
+ filter: `ref_doc_id = "${refDocId}"`
102
+ }, {
103
+ namespace: this.namespace
104
+ });
105
+ // Delete all matching nodes by their IDs
106
+ const idsToDelete = results.map((r)=>String(r.id));
107
+ if (idsToDelete.length > 0) {
108
+ await this.db.namespace(this.namespace).delete(idsToDelete);
109
+ }
98
110
  }
99
111
  /**
100
- * Deletes a single record from the database by id.
101
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
102
- * @param refDocId Unique identifier for the record to delete.
103
- * @param deleteKwargs Required by VectorStore interface. Currently ignored.
112
+ * Deletes multiple records from the database by their IDs.
113
+ * @param ids Array of node IDs to delete.
104
114
  * @returns Promise that resolves if the delete query did not throw an error.
105
- */ async deleteMany(refDocId) {
106
- await this.db.namespace(this.namespace).delete(refDocId);
115
+ */ async deleteMany(ids) {
116
+ await this.db.namespace(this.namespace).delete(ids);
107
117
  }
108
118
  /**
109
119
  * Query the vector store for the closest matching data to the query embeddings
@@ -176,6 +186,17 @@ var env = require('@vectorstores/env');
176
186
  metadata: core.nodeToMetadata(node)
177
187
  };
178
188
  }
189
+ async exists(refDocId) {
190
+ const results = await this.db.query({
191
+ vector: new Array(1536).fill(0),
192
+ topK: 1,
193
+ includeMetadata: false,
194
+ filter: `ref_doc_id = "${refDocId}"`
195
+ }, {
196
+ namespace: this.namespace
197
+ });
198
+ return results.length > 0;
199
+ }
179
200
  }
180
201
 
181
202
  exports.UpstashVectorStore = UpstashVectorStore;
package/dist/index.d.cts CHANGED
@@ -47,20 +47,17 @@ declare class UpstashVectorStore extends BaseVectorStore {
47
47
  addPlainText(text: TextNode<Metadata>[]): Promise<string[]>;
48
48
  private upsertInBatches;
49
49
  /**
50
- * Deletes a single record from the database by id.
51
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
52
- * @param refDocId Unique identifier for the record to delete.
50
+ * Deletes all nodes from the database that belong to the given document.
51
+ * @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
53
52
  * @returns Promise that resolves if the delete query did not throw an error.
54
53
  */
55
54
  delete(refDocId: string): Promise<void>;
56
55
  /**
57
- * Deletes a single record from the database by id.
58
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
59
- * @param refDocId Unique identifier for the record to delete.
60
- * @param deleteKwargs Required by VectorStore interface. Currently ignored.
56
+ * Deletes multiple records from the database by their IDs.
57
+ * @param ids Array of node IDs to delete.
61
58
  * @returns Promise that resolves if the delete query did not throw an error.
62
59
  */
63
- deleteMany(refDocId: string[]): Promise<void>;
60
+ deleteMany(ids: string[]): Promise<void>;
64
61
  /**
65
62
  * Query the vector store for the closest matching data to the query embeddings
66
63
  * @param query The VectorStoreQuery to be used
@@ -80,6 +77,7 @@ declare class UpstashVectorStore extends BaseVectorStore {
80
77
  data: string;
81
78
  metadata: Metadata;
82
79
  };
80
+ exists(refDocId: string): Promise<boolean>;
83
81
  }
84
82
 
85
83
  export { UpstashVectorStore };
package/dist/index.d.ts CHANGED
@@ -47,20 +47,17 @@ declare class UpstashVectorStore extends BaseVectorStore {
47
47
  addPlainText(text: TextNode<Metadata>[]): Promise<string[]>;
48
48
  private upsertInBatches;
49
49
  /**
50
- * Deletes a single record from the database by id.
51
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
52
- * @param refDocId Unique identifier for the record to delete.
50
+ * Deletes all nodes from the database that belong to the given document.
51
+ * @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
53
52
  * @returns Promise that resolves if the delete query did not throw an error.
54
53
  */
55
54
  delete(refDocId: string): Promise<void>;
56
55
  /**
57
- * Deletes a single record from the database by id.
58
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
59
- * @param refDocId Unique identifier for the record to delete.
60
- * @param deleteKwargs Required by VectorStore interface. Currently ignored.
56
+ * Deletes multiple records from the database by their IDs.
57
+ * @param ids Array of node IDs to delete.
61
58
  * @returns Promise that resolves if the delete query did not throw an error.
62
59
  */
63
- deleteMany(refDocId: string[]): Promise<void>;
60
+ deleteMany(ids: string[]): Promise<void>;
64
61
  /**
65
62
  * Query the vector store for the closest matching data to the query embeddings
66
63
  * @param query The VectorStoreQuery to be used
@@ -80,6 +77,7 @@ declare class UpstashVectorStore extends BaseVectorStore {
80
77
  data: string;
81
78
  metadata: Metadata;
82
79
  };
80
+ exists(refDocId: string): Promise<boolean>;
83
81
  }
84
82
 
85
83
  export { UpstashVectorStore };
@@ -47,20 +47,17 @@ declare class UpstashVectorStore extends BaseVectorStore {
47
47
  addPlainText(text: TextNode<Metadata>[]): Promise<string[]>;
48
48
  private upsertInBatches;
49
49
  /**
50
- * Deletes a single record from the database by id.
51
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
52
- * @param refDocId Unique identifier for the record to delete.
50
+ * Deletes all nodes from the database that belong to the given document.
51
+ * @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
53
52
  * @returns Promise that resolves if the delete query did not throw an error.
54
53
  */
55
54
  delete(refDocId: string): Promise<void>;
56
55
  /**
57
- * Deletes a single record from the database by id.
58
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
59
- * @param refDocId Unique identifier for the record to delete.
60
- * @param deleteKwargs Required by VectorStore interface. Currently ignored.
56
+ * Deletes multiple records from the database by their IDs.
57
+ * @param ids Array of node IDs to delete.
61
58
  * @returns Promise that resolves if the delete query did not throw an error.
62
59
  */
63
- deleteMany(refDocId: string[]): Promise<void>;
60
+ deleteMany(ids: string[]): Promise<void>;
64
61
  /**
65
62
  * Query the vector store for the closest matching data to the query embeddings
66
63
  * @param query The VectorStoreQuery to be used
@@ -80,6 +77,7 @@ declare class UpstashVectorStore extends BaseVectorStore {
80
77
  data: string;
81
78
  metadata: Metadata;
82
79
  };
80
+ exists(refDocId: string): Promise<boolean>;
83
81
  }
84
82
 
85
83
  export { UpstashVectorStore };
@@ -87,21 +87,31 @@ import { getEnv } from '@vectorstores/env';
87
87
  return results.every((result)=>result === "OK") ? "OK" : "NOT-OK";
88
88
  }
89
89
  /**
90
- * Deletes a single record from the database by id.
91
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
92
- * @param refDocId Unique identifier for the record to delete.
90
+ * Deletes all nodes from the database that belong to the given document.
91
+ * @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
93
92
  * @returns Promise that resolves if the delete query did not throw an error.
94
93
  */ async delete(refDocId) {
95
- await this.db.namespace(this.namespace).delete(refDocId);
94
+ // Query to find all node IDs with this ref_doc_id
95
+ const results = await this.db.query({
96
+ vector: new Array(1536).fill(0),
97
+ topK: 10000,
98
+ includeMetadata: true,
99
+ filter: `ref_doc_id = "${refDocId}"`
100
+ }, {
101
+ namespace: this.namespace
102
+ });
103
+ // Delete all matching nodes by their IDs
104
+ const idsToDelete = results.map((r)=>String(r.id));
105
+ if (idsToDelete.length > 0) {
106
+ await this.db.namespace(this.namespace).delete(idsToDelete);
107
+ }
96
108
  }
97
109
  /**
98
- * Deletes a single record from the database by id.
99
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
100
- * @param refDocId Unique identifier for the record to delete.
101
- * @param deleteKwargs Required by VectorStore interface. Currently ignored.
110
+ * Deletes multiple records from the database by their IDs.
111
+ * @param ids Array of node IDs to delete.
102
112
  * @returns Promise that resolves if the delete query did not throw an error.
103
- */ async deleteMany(refDocId) {
104
- await this.db.namespace(this.namespace).delete(refDocId);
113
+ */ async deleteMany(ids) {
114
+ await this.db.namespace(this.namespace).delete(ids);
105
115
  }
106
116
  /**
107
117
  * Query the vector store for the closest matching data to the query embeddings
@@ -174,6 +184,17 @@ import { getEnv } from '@vectorstores/env';
174
184
  metadata: nodeToMetadata(node)
175
185
  };
176
186
  }
187
+ async exists(refDocId) {
188
+ const results = await this.db.query({
189
+ vector: new Array(1536).fill(0),
190
+ topK: 1,
191
+ includeMetadata: false,
192
+ filter: `ref_doc_id = "${refDocId}"`
193
+ }, {
194
+ namespace: this.namespace
195
+ });
196
+ return results.length > 0;
197
+ }
177
198
  }
178
199
 
179
200
  export { UpstashVectorStore };
package/dist/index.js CHANGED
@@ -87,21 +87,31 @@ import { getEnv } from '@vectorstores/env';
87
87
  return results.every((result)=>result === "OK") ? "OK" : "NOT-OK";
88
88
  }
89
89
  /**
90
- * Deletes a single record from the database by id.
91
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
92
- * @param refDocId Unique identifier for the record to delete.
90
+ * Deletes all nodes from the database that belong to the given document.
91
+ * @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
93
92
  * @returns Promise that resolves if the delete query did not throw an error.
94
93
  */ async delete(refDocId) {
95
- await this.db.namespace(this.namespace).delete(refDocId);
94
+ // Query to find all node IDs with this ref_doc_id
95
+ const results = await this.db.query({
96
+ vector: new Array(1536).fill(0),
97
+ topK: 10000,
98
+ includeMetadata: true,
99
+ filter: `ref_doc_id = "${refDocId}"`
100
+ }, {
101
+ namespace: this.namespace
102
+ });
103
+ // Delete all matching nodes by their IDs
104
+ const idsToDelete = results.map((r)=>String(r.id));
105
+ if (idsToDelete.length > 0) {
106
+ await this.db.namespace(this.namespace).delete(idsToDelete);
107
+ }
96
108
  }
97
109
  /**
98
- * Deletes a single record from the database by id.
99
- * NOTE: Uses the collection property controlled by setCollection/getCollection.
100
- * @param refDocId Unique identifier for the record to delete.
101
- * @param deleteKwargs Required by VectorStore interface. Currently ignored.
110
+ * Deletes multiple records from the database by their IDs.
111
+ * @param ids Array of node IDs to delete.
102
112
  * @returns Promise that resolves if the delete query did not throw an error.
103
- */ async deleteMany(refDocId) {
104
- await this.db.namespace(this.namespace).delete(refDocId);
113
+ */ async deleteMany(ids) {
114
+ await this.db.namespace(this.namespace).delete(ids);
105
115
  }
106
116
  /**
107
117
  * Query the vector store for the closest matching data to the query embeddings
@@ -174,6 +184,17 @@ import { getEnv } from '@vectorstores/env';
174
184
  metadata: nodeToMetadata(node)
175
185
  };
176
186
  }
187
+ async exists(refDocId) {
188
+ const results = await this.db.query({
189
+ vector: new Array(1536).fill(0),
190
+ topK: 1,
191
+ includeMetadata: false,
192
+ filter: `ref_doc_id = "${refDocId}"`
193
+ }, {
194
+ namespace: this.namespace
195
+ });
196
+ return results.length > 0;
197
+ }
177
198
  }
178
199
 
179
200
  export { UpstashVectorStore };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vectorstores/upstash",
3
3
  "description": "Upstash Storage for vectorstores",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -34,11 +34,11 @@
34
34
  "directory": "packages/providers/storage/upstash"
35
35
  },
36
36
  "devDependencies": {
37
- "@vectorstores/core": "0.1.3",
37
+ "@vectorstores/core": "0.1.4",
38
38
  "@vectorstores/env": "0.1.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@vectorstores/core": "0.1.3",
41
+ "@vectorstores/core": "0.1.4",
42
42
  "@vectorstores/env": "0.1.0"
43
43
  },
44
44
  "dependencies": {