@vectorstores/azure 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 +58 -11
- package/dist/index.d.cts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.edge-light.d.ts +11 -7
- package/dist/index.edge-light.js +58 -11
- package/dist/index.js +58 -11
- package/dist/storage.cjs +1 -214
- package/dist/storage.d.cts +3 -121
- package/dist/storage.d.ts +3 -121
- package/dist/storage.edge-light.d.ts +3 -121
- package/dist/storage.edge-light.js +3 -212
- package/dist/storage.js +3 -212
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
|
|
3
3
|
var core = require('@vectorstores/core');
|
|
4
4
|
var storage_cjs = require('./storage.cjs');
|
|
5
|
-
var searchDocuments = require('@azure/search-documents');
|
|
6
5
|
var identity = require('@azure/identity');
|
|
6
|
+
var searchDocuments = require('@azure/search-documents');
|
|
7
7
|
var env = require('@vectorstores/env');
|
|
8
8
|
var mongodb = require('mongodb');
|
|
9
9
|
var cosmos = require('@azure/cosmos');
|
|
@@ -789,7 +789,7 @@ console.log({ response });
|
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
#buildCredentials(options) {
|
|
792
|
-
let { credential
|
|
792
|
+
let { credential, key, endpoint, indexName } = options;
|
|
793
793
|
// validate and use credential
|
|
794
794
|
if (credential) {
|
|
795
795
|
// if credential are provided, ensure they are an instance of valid credential instances
|
|
@@ -1121,9 +1121,19 @@ console.log({ response });
|
|
|
1121
1121
|
// Execute the search and return the result
|
|
1122
1122
|
return await azureQueryResultSearch.search();
|
|
1123
1123
|
}
|
|
1124
|
+
async exists(refDocId) {
|
|
1125
|
+
const results = await this._searchClient.search("*", {
|
|
1126
|
+
filter: `ref_doc_id eq '${refDocId}'`,
|
|
1127
|
+
top: 1
|
|
1128
|
+
});
|
|
1129
|
+
for await (const _result of results.results){
|
|
1130
|
+
return true;
|
|
1131
|
+
}
|
|
1132
|
+
return false;
|
|
1133
|
+
}
|
|
1124
1134
|
}
|
|
1125
1135
|
|
|
1126
|
-
var version = "0.1.
|
|
1136
|
+
var version = "0.1.4";
|
|
1127
1137
|
var pkg = {
|
|
1128
1138
|
version: version};
|
|
1129
1139
|
|
|
@@ -1206,13 +1216,14 @@ var pkg = {
|
|
|
1206
1216
|
return Object.values(insertResult.insertedIds).map((id)=>String(id));
|
|
1207
1217
|
}
|
|
1208
1218
|
/**
|
|
1209
|
-
*
|
|
1210
|
-
* @param
|
|
1219
|
+
* Deletes all nodes from the collection that belong to the given document.
|
|
1220
|
+
* @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
1221
|
+
* @param deleteOptions Additional delete options.
|
|
1211
1222
|
* @returns A promise that resolves when the documents have been removed.
|
|
1212
|
-
*/ async delete(
|
|
1223
|
+
*/ async delete(refDocId, deleteOptions) {
|
|
1213
1224
|
const collection = await this.ensureCollection();
|
|
1214
1225
|
await collection.deleteMany({
|
|
1215
|
-
|
|
1226
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
1216
1227
|
}, deleteOptions);
|
|
1217
1228
|
}
|
|
1218
1229
|
async query(query, options) {
|
|
@@ -1350,6 +1361,15 @@ var pkg = {
|
|
|
1350
1361
|
await collection.dropIndex(indexName);
|
|
1351
1362
|
}
|
|
1352
1363
|
}
|
|
1364
|
+
async exists(refDocId) {
|
|
1365
|
+
const collection = await this.ensureCollection();
|
|
1366
|
+
const count = await collection.countDocuments({
|
|
1367
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
1368
|
+
}, {
|
|
1369
|
+
limit: 1
|
|
1370
|
+
});
|
|
1371
|
+
return count > 0;
|
|
1372
|
+
}
|
|
1353
1373
|
}
|
|
1354
1374
|
|
|
1355
1375
|
const USER_AGENT_SUFFIX = "vectorstores-cdbnosql-vectorstore-javascript";
|
|
@@ -1532,14 +1552,28 @@ class AzureCosmosDBNoSqlVectorStore extends core.BaseVectorStore {
|
|
|
1532
1552
|
return ids;
|
|
1533
1553
|
}
|
|
1534
1554
|
/**
|
|
1535
|
-
* Delete
|
|
1555
|
+
* Delete all nodes from the CosmosDB container that belong to the given document.
|
|
1536
1556
|
*
|
|
1537
|
-
* @param refDocId -
|
|
1538
|
-
* @param deleteOptions - Any options to pass to the
|
|
1557
|
+
* @param refDocId - Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
1558
|
+
* @param deleteOptions - Any options to pass to the delete operations.
|
|
1539
1559
|
* @returns Promise that resolves if the delete query did not throw an error.
|
|
1540
1560
|
*/ async delete(refDocId, deleteOptions) {
|
|
1541
1561
|
await this.initialize();
|
|
1542
|
-
|
|
1562
|
+
// Query all items with matching ref_doc_id
|
|
1563
|
+
const querySpec = {
|
|
1564
|
+
query: `SELECT c.id FROM c WHERE c.metadata.ref_doc_id = @refDocId`,
|
|
1565
|
+
parameters: [
|
|
1566
|
+
{
|
|
1567
|
+
name: "@refDocId",
|
|
1568
|
+
value: refDocId
|
|
1569
|
+
}
|
|
1570
|
+
]
|
|
1571
|
+
};
|
|
1572
|
+
const { resources: items } = await this.container.items.query(querySpec).fetchAll();
|
|
1573
|
+
// Delete each matching item
|
|
1574
|
+
for (const item of items){
|
|
1575
|
+
await this.container.item(item.id, item.id).delete(deleteOptions);
|
|
1576
|
+
}
|
|
1543
1577
|
}
|
|
1544
1578
|
/**
|
|
1545
1579
|
* Performs a vector similarity search query in the CosmosDB container.
|
|
@@ -1633,6 +1667,19 @@ class AzureCosmosDBNoSqlVectorStore extends core.BaseVectorStore {
|
|
|
1633
1667
|
});
|
|
1634
1668
|
this.container = container;
|
|
1635
1669
|
}
|
|
1670
|
+
async exists(refDocId) {
|
|
1671
|
+
await this.initialize();
|
|
1672
|
+
const { resources } = await this.container.items.query({
|
|
1673
|
+
query: `SELECT VALUE COUNT(1) FROM c WHERE c.metadata.ref_doc_id = @refDocId`,
|
|
1674
|
+
parameters: [
|
|
1675
|
+
{
|
|
1676
|
+
name: "@refDocId",
|
|
1677
|
+
value: refDocId
|
|
1678
|
+
}
|
|
1679
|
+
]
|
|
1680
|
+
}).fetchAll();
|
|
1681
|
+
return (resources[0] ?? 0) > 0;
|
|
1682
|
+
}
|
|
1636
1683
|
}
|
|
1637
1684
|
|
|
1638
1685
|
exports.AzureAISearchVectorStore = AzureAISearchVectorStore;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SqlQuerySpec, CosmosClient, DatabaseRequest, ContainerRequest, VectorEmbeddingPolicy, IndexingPolicy } from '@azure/cosmos';
|
|
2
2
|
import { BaseReader, Document, BaseNode, BaseVectorStore, VectorStoreBaseParams, MetadataFilters, VectorStoreQuery, VectorStoreQueryResult } from '@vectorstores/core';
|
|
3
3
|
export * from './storage.cjs';
|
|
4
|
-
import { AzureKeyCredential, SearchIndexClient, SearchClient, LexicalAnalyzerName, KnownVectorSearchCompressionKind, KnownVectorSearchAlgorithmKind, VectorizedQuery } from '@azure/search-documents';
|
|
5
4
|
import { DefaultAzureCredential, ManagedIdentityCredential, TokenCredential } from '@azure/identity';
|
|
5
|
+
import { AzureKeyCredential, SearchIndexClient, SearchClient, LexicalAnalyzerName, KnownVectorSearchCompressionKind, KnownVectorSearchAlgorithmKind, VectorizedQuery } from '@azure/search-documents';
|
|
6
6
|
import { MongoClient, Collection } from 'mongodb';
|
|
7
7
|
|
|
8
8
|
type SimpleCosmosDBReaderLoaderConfig = {
|
|
@@ -303,6 +303,7 @@ declare class AzureAISearchVectorStore<T extends R> extends BaseVectorStore {
|
|
|
303
303
|
query(query: VectorStoreQuery & {
|
|
304
304
|
queryStr: string;
|
|
305
305
|
}): Promise<VectorStoreQueryResult>;
|
|
306
|
+
exists(refDocId: string): Promise<boolean>;
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
/** Azure Cosmos DB for MongoDB vCore Similarity type. */
|
|
@@ -388,11 +389,12 @@ declare class AzureCosmosDBMongoDBVectorStore extends BaseVectorStore {
|
|
|
388
389
|
ensureCollection(): Promise<Collection>;
|
|
389
390
|
add(nodes: BaseNode[]): Promise<string[]>;
|
|
390
391
|
/**
|
|
391
|
-
*
|
|
392
|
-
* @param
|
|
392
|
+
* Deletes all nodes from the collection that belong to the given document.
|
|
393
|
+
* @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
394
|
+
* @param deleteOptions Additional delete options.
|
|
393
395
|
* @returns A promise that resolves when the documents have been removed.
|
|
394
396
|
*/
|
|
395
|
-
delete(
|
|
397
|
+
delete(refDocId: string, deleteOptions?: object): Promise<void>;
|
|
396
398
|
query(query: VectorStoreQuery, options: AzureCosmosDBMongoDBQueryOptions): Promise<VectorStoreQueryResult>;
|
|
397
399
|
/**
|
|
398
400
|
* Creates an index on the collection with the specified index name during
|
|
@@ -435,6 +437,7 @@ declare class AzureCosmosDBMongoDBVectorStore extends BaseVectorStore {
|
|
|
435
437
|
* @returns A promise that resolves when the index has been deleted.
|
|
436
438
|
*/
|
|
437
439
|
deleteIndex(indexName: string): Promise<void>;
|
|
440
|
+
exists(refDocId: string): Promise<boolean>;
|
|
438
441
|
}
|
|
439
442
|
|
|
440
443
|
/** Azure Cosmos DB for NoSQL database creation options. */
|
|
@@ -534,10 +537,10 @@ declare class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
534
537
|
*/
|
|
535
538
|
add(nodes: BaseNode[]): Promise<string[]>;
|
|
536
539
|
/**
|
|
537
|
-
* Delete
|
|
540
|
+
* Delete all nodes from the CosmosDB container that belong to the given document.
|
|
538
541
|
*
|
|
539
|
-
* @param refDocId -
|
|
540
|
-
* @param deleteOptions - Any options to pass to the
|
|
542
|
+
* @param refDocId - Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
543
|
+
* @param deleteOptions - Any options to pass to the delete operations.
|
|
541
544
|
* @returns Promise that resolves if the delete query did not throw an error.
|
|
542
545
|
*/
|
|
543
546
|
delete(refDocId: string, deleteOptions?: object): Promise<void>;
|
|
@@ -552,6 +555,7 @@ declare class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
552
555
|
* Initialize the CosmosDB container.
|
|
553
556
|
*/
|
|
554
557
|
private init;
|
|
558
|
+
exists(refDocId: string): Promise<boolean>;
|
|
555
559
|
}
|
|
556
560
|
|
|
557
561
|
declare class AzureQueryResultSearchBase<T extends R> {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SqlQuerySpec, CosmosClient, DatabaseRequest, ContainerRequest, VectorEmbeddingPolicy, IndexingPolicy } from '@azure/cosmos';
|
|
2
2
|
import { BaseReader, Document, BaseNode, BaseVectorStore, VectorStoreBaseParams, MetadataFilters, VectorStoreQuery, VectorStoreQueryResult } from '@vectorstores/core';
|
|
3
3
|
export * from './storage.js';
|
|
4
|
-
import { AzureKeyCredential, SearchIndexClient, SearchClient, LexicalAnalyzerName, KnownVectorSearchCompressionKind, KnownVectorSearchAlgorithmKind, VectorizedQuery } from '@azure/search-documents';
|
|
5
4
|
import { DefaultAzureCredential, ManagedIdentityCredential, TokenCredential } from '@azure/identity';
|
|
5
|
+
import { AzureKeyCredential, SearchIndexClient, SearchClient, LexicalAnalyzerName, KnownVectorSearchCompressionKind, KnownVectorSearchAlgorithmKind, VectorizedQuery } from '@azure/search-documents';
|
|
6
6
|
import { MongoClient, Collection } from 'mongodb';
|
|
7
7
|
|
|
8
8
|
type SimpleCosmosDBReaderLoaderConfig = {
|
|
@@ -303,6 +303,7 @@ declare class AzureAISearchVectorStore<T extends R> extends BaseVectorStore {
|
|
|
303
303
|
query(query: VectorStoreQuery & {
|
|
304
304
|
queryStr: string;
|
|
305
305
|
}): Promise<VectorStoreQueryResult>;
|
|
306
|
+
exists(refDocId: string): Promise<boolean>;
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
/** Azure Cosmos DB for MongoDB vCore Similarity type. */
|
|
@@ -388,11 +389,12 @@ declare class AzureCosmosDBMongoDBVectorStore extends BaseVectorStore {
|
|
|
388
389
|
ensureCollection(): Promise<Collection>;
|
|
389
390
|
add(nodes: BaseNode[]): Promise<string[]>;
|
|
390
391
|
/**
|
|
391
|
-
*
|
|
392
|
-
* @param
|
|
392
|
+
* Deletes all nodes from the collection that belong to the given document.
|
|
393
|
+
* @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
394
|
+
* @param deleteOptions Additional delete options.
|
|
393
395
|
* @returns A promise that resolves when the documents have been removed.
|
|
394
396
|
*/
|
|
395
|
-
delete(
|
|
397
|
+
delete(refDocId: string, deleteOptions?: object): Promise<void>;
|
|
396
398
|
query(query: VectorStoreQuery, options: AzureCosmosDBMongoDBQueryOptions): Promise<VectorStoreQueryResult>;
|
|
397
399
|
/**
|
|
398
400
|
* Creates an index on the collection with the specified index name during
|
|
@@ -435,6 +437,7 @@ declare class AzureCosmosDBMongoDBVectorStore extends BaseVectorStore {
|
|
|
435
437
|
* @returns A promise that resolves when the index has been deleted.
|
|
436
438
|
*/
|
|
437
439
|
deleteIndex(indexName: string): Promise<void>;
|
|
440
|
+
exists(refDocId: string): Promise<boolean>;
|
|
438
441
|
}
|
|
439
442
|
|
|
440
443
|
/** Azure Cosmos DB for NoSQL database creation options. */
|
|
@@ -534,10 +537,10 @@ declare class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
534
537
|
*/
|
|
535
538
|
add(nodes: BaseNode[]): Promise<string[]>;
|
|
536
539
|
/**
|
|
537
|
-
* Delete
|
|
540
|
+
* Delete all nodes from the CosmosDB container that belong to the given document.
|
|
538
541
|
*
|
|
539
|
-
* @param refDocId -
|
|
540
|
-
* @param deleteOptions - Any options to pass to the
|
|
542
|
+
* @param refDocId - Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
543
|
+
* @param deleteOptions - Any options to pass to the delete operations.
|
|
541
544
|
* @returns Promise that resolves if the delete query did not throw an error.
|
|
542
545
|
*/
|
|
543
546
|
delete(refDocId: string, deleteOptions?: object): Promise<void>;
|
|
@@ -552,6 +555,7 @@ declare class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
552
555
|
* Initialize the CosmosDB container.
|
|
553
556
|
*/
|
|
554
557
|
private init;
|
|
558
|
+
exists(refDocId: string): Promise<boolean>;
|
|
555
559
|
}
|
|
556
560
|
|
|
557
561
|
declare class AzureQueryResultSearchBase<T extends R> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SqlQuerySpec, CosmosClient, DatabaseRequest, ContainerRequest, VectorEmbeddingPolicy, IndexingPolicy } from '@azure/cosmos';
|
|
2
2
|
import { BaseReader, Document, BaseNode, BaseVectorStore, VectorStoreBaseParams, MetadataFilters, VectorStoreQuery, VectorStoreQueryResult } from '@vectorstores/core';
|
|
3
3
|
export * from './storage.js';
|
|
4
|
-
import { AzureKeyCredential, SearchIndexClient, SearchClient, LexicalAnalyzerName, KnownVectorSearchCompressionKind, KnownVectorSearchAlgorithmKind, VectorizedQuery } from '@azure/search-documents';
|
|
5
4
|
import { DefaultAzureCredential, ManagedIdentityCredential, TokenCredential } from '@azure/identity';
|
|
5
|
+
import { AzureKeyCredential, SearchIndexClient, SearchClient, LexicalAnalyzerName, KnownVectorSearchCompressionKind, KnownVectorSearchAlgorithmKind, VectorizedQuery } from '@azure/search-documents';
|
|
6
6
|
import { MongoClient, Collection } from 'mongodb';
|
|
7
7
|
|
|
8
8
|
type SimpleCosmosDBReaderLoaderConfig = {
|
|
@@ -303,6 +303,7 @@ declare class AzureAISearchVectorStore<T extends R> extends BaseVectorStore {
|
|
|
303
303
|
query(query: VectorStoreQuery & {
|
|
304
304
|
queryStr: string;
|
|
305
305
|
}): Promise<VectorStoreQueryResult>;
|
|
306
|
+
exists(refDocId: string): Promise<boolean>;
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
/** Azure Cosmos DB for MongoDB vCore Similarity type. */
|
|
@@ -388,11 +389,12 @@ declare class AzureCosmosDBMongoDBVectorStore extends BaseVectorStore {
|
|
|
388
389
|
ensureCollection(): Promise<Collection>;
|
|
389
390
|
add(nodes: BaseNode[]): Promise<string[]>;
|
|
390
391
|
/**
|
|
391
|
-
*
|
|
392
|
-
* @param
|
|
392
|
+
* Deletes all nodes from the collection that belong to the given document.
|
|
393
|
+
* @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
394
|
+
* @param deleteOptions Additional delete options.
|
|
393
395
|
* @returns A promise that resolves when the documents have been removed.
|
|
394
396
|
*/
|
|
395
|
-
delete(
|
|
397
|
+
delete(refDocId: string, deleteOptions?: object): Promise<void>;
|
|
396
398
|
query(query: VectorStoreQuery, options: AzureCosmosDBMongoDBQueryOptions): Promise<VectorStoreQueryResult>;
|
|
397
399
|
/**
|
|
398
400
|
* Creates an index on the collection with the specified index name during
|
|
@@ -435,6 +437,7 @@ declare class AzureCosmosDBMongoDBVectorStore extends BaseVectorStore {
|
|
|
435
437
|
* @returns A promise that resolves when the index has been deleted.
|
|
436
438
|
*/
|
|
437
439
|
deleteIndex(indexName: string): Promise<void>;
|
|
440
|
+
exists(refDocId: string): Promise<boolean>;
|
|
438
441
|
}
|
|
439
442
|
|
|
440
443
|
/** Azure Cosmos DB for NoSQL database creation options. */
|
|
@@ -534,10 +537,10 @@ declare class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
534
537
|
*/
|
|
535
538
|
add(nodes: BaseNode[]): Promise<string[]>;
|
|
536
539
|
/**
|
|
537
|
-
* Delete
|
|
540
|
+
* Delete all nodes from the CosmosDB container that belong to the given document.
|
|
538
541
|
*
|
|
539
|
-
* @param refDocId -
|
|
540
|
-
* @param deleteOptions - Any options to pass to the
|
|
542
|
+
* @param refDocId - Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
543
|
+
* @param deleteOptions - Any options to pass to the delete operations.
|
|
541
544
|
* @returns Promise that resolves if the delete query did not throw an error.
|
|
542
545
|
*/
|
|
543
546
|
delete(refDocId: string, deleteOptions?: object): Promise<void>;
|
|
@@ -552,6 +555,7 @@ declare class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
552
555
|
* Initialize the CosmosDB container.
|
|
553
556
|
*/
|
|
554
557
|
private init;
|
|
558
|
+
exists(refDocId: string): Promise<boolean>;
|
|
555
559
|
}
|
|
556
560
|
|
|
557
561
|
declare class AzureQueryResultSearchBase<T extends R> {
|
package/dist/index.edge-light.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Document, metadataDictToNode, BaseVectorStore, MetadataMode, nodeToMetadata, FilterOperator, FilterCondition, VectorStoreQueryMode } from '@vectorstores/core';
|
|
2
2
|
export * from './storage.edge-light.js';
|
|
3
|
-
import { KnownVectorSearchAlgorithmKind, KnownAnalyzerNames, KnownSearchFieldDataType, KnownVectorSearchAlgorithmMetric, KnownVectorSearchCompressionKind, SearchClient, SearchIndexClient, AzureKeyCredential, IndexDocumentsBatch } from '@azure/search-documents';
|
|
4
3
|
import { DefaultAzureCredential, ManagedIdentityCredential } from '@azure/identity';
|
|
4
|
+
import { KnownVectorSearchAlgorithmKind, KnownAnalyzerNames, KnownSearchFieldDataType, KnownVectorSearchAlgorithmMetric, KnownVectorSearchCompressionKind, SearchClient, SearchIndexClient, AzureKeyCredential, IndexDocumentsBatch } from '@azure/search-documents';
|
|
5
5
|
import { consoleLogger, getEnv } from '@vectorstores/env';
|
|
6
6
|
import { MongoClient } from 'mongodb';
|
|
7
7
|
import { VectorEmbeddingDistanceFunction, VectorEmbeddingDataType, VectorIndexType, CosmosClient } from '@azure/cosmos';
|
|
@@ -787,7 +787,7 @@ console.log({ response });
|
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
789
|
#buildCredentials(options) {
|
|
790
|
-
let { credential
|
|
790
|
+
let { credential, key, endpoint, indexName } = options;
|
|
791
791
|
// validate and use credential
|
|
792
792
|
if (credential) {
|
|
793
793
|
// if credential are provided, ensure they are an instance of valid credential instances
|
|
@@ -1119,9 +1119,19 @@ console.log({ response });
|
|
|
1119
1119
|
// Execute the search and return the result
|
|
1120
1120
|
return await azureQueryResultSearch.search();
|
|
1121
1121
|
}
|
|
1122
|
+
async exists(refDocId) {
|
|
1123
|
+
const results = await this._searchClient.search("*", {
|
|
1124
|
+
filter: `ref_doc_id eq '${refDocId}'`,
|
|
1125
|
+
top: 1
|
|
1126
|
+
});
|
|
1127
|
+
for await (const _result of results.results){
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
return false;
|
|
1131
|
+
}
|
|
1122
1132
|
}
|
|
1123
1133
|
|
|
1124
|
-
var version = "0.1.
|
|
1134
|
+
var version = "0.1.4";
|
|
1125
1135
|
var pkg = {
|
|
1126
1136
|
version: version};
|
|
1127
1137
|
|
|
@@ -1204,13 +1214,14 @@ var pkg = {
|
|
|
1204
1214
|
return Object.values(insertResult.insertedIds).map((id)=>String(id));
|
|
1205
1215
|
}
|
|
1206
1216
|
/**
|
|
1207
|
-
*
|
|
1208
|
-
* @param
|
|
1217
|
+
* Deletes all nodes from the collection that belong to the given document.
|
|
1218
|
+
* @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
1219
|
+
* @param deleteOptions Additional delete options.
|
|
1209
1220
|
* @returns A promise that resolves when the documents have been removed.
|
|
1210
|
-
*/ async delete(
|
|
1221
|
+
*/ async delete(refDocId, deleteOptions) {
|
|
1211
1222
|
const collection = await this.ensureCollection();
|
|
1212
1223
|
await collection.deleteMany({
|
|
1213
|
-
|
|
1224
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
1214
1225
|
}, deleteOptions);
|
|
1215
1226
|
}
|
|
1216
1227
|
async query(query, options) {
|
|
@@ -1348,6 +1359,15 @@ var pkg = {
|
|
|
1348
1359
|
await collection.dropIndex(indexName);
|
|
1349
1360
|
}
|
|
1350
1361
|
}
|
|
1362
|
+
async exists(refDocId) {
|
|
1363
|
+
const collection = await this.ensureCollection();
|
|
1364
|
+
const count = await collection.countDocuments({
|
|
1365
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
1366
|
+
}, {
|
|
1367
|
+
limit: 1
|
|
1368
|
+
});
|
|
1369
|
+
return count > 0;
|
|
1370
|
+
}
|
|
1351
1371
|
}
|
|
1352
1372
|
|
|
1353
1373
|
const USER_AGENT_SUFFIX = "vectorstores-cdbnosql-vectorstore-javascript";
|
|
@@ -1530,14 +1550,28 @@ class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
1530
1550
|
return ids;
|
|
1531
1551
|
}
|
|
1532
1552
|
/**
|
|
1533
|
-
* Delete
|
|
1553
|
+
* Delete all nodes from the CosmosDB container that belong to the given document.
|
|
1534
1554
|
*
|
|
1535
|
-
* @param refDocId -
|
|
1536
|
-
* @param deleteOptions - Any options to pass to the
|
|
1555
|
+
* @param refDocId - Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
1556
|
+
* @param deleteOptions - Any options to pass to the delete operations.
|
|
1537
1557
|
* @returns Promise that resolves if the delete query did not throw an error.
|
|
1538
1558
|
*/ async delete(refDocId, deleteOptions) {
|
|
1539
1559
|
await this.initialize();
|
|
1540
|
-
|
|
1560
|
+
// Query all items with matching ref_doc_id
|
|
1561
|
+
const querySpec = {
|
|
1562
|
+
query: `SELECT c.id FROM c WHERE c.metadata.ref_doc_id = @refDocId`,
|
|
1563
|
+
parameters: [
|
|
1564
|
+
{
|
|
1565
|
+
name: "@refDocId",
|
|
1566
|
+
value: refDocId
|
|
1567
|
+
}
|
|
1568
|
+
]
|
|
1569
|
+
};
|
|
1570
|
+
const { resources: items } = await this.container.items.query(querySpec).fetchAll();
|
|
1571
|
+
// Delete each matching item
|
|
1572
|
+
for (const item of items){
|
|
1573
|
+
await this.container.item(item.id, item.id).delete(deleteOptions);
|
|
1574
|
+
}
|
|
1541
1575
|
}
|
|
1542
1576
|
/**
|
|
1543
1577
|
* Performs a vector similarity search query in the CosmosDB container.
|
|
@@ -1631,6 +1665,19 @@ class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
1631
1665
|
});
|
|
1632
1666
|
this.container = container;
|
|
1633
1667
|
}
|
|
1668
|
+
async exists(refDocId) {
|
|
1669
|
+
await this.initialize();
|
|
1670
|
+
const { resources } = await this.container.items.query({
|
|
1671
|
+
query: `SELECT VALUE COUNT(1) FROM c WHERE c.metadata.ref_doc_id = @refDocId`,
|
|
1672
|
+
parameters: [
|
|
1673
|
+
{
|
|
1674
|
+
name: "@refDocId",
|
|
1675
|
+
value: refDocId
|
|
1676
|
+
}
|
|
1677
|
+
]
|
|
1678
|
+
}).fetchAll();
|
|
1679
|
+
return (resources[0] ?? 0) > 0;
|
|
1680
|
+
}
|
|
1634
1681
|
}
|
|
1635
1682
|
|
|
1636
1683
|
export { AzureAISearchVectorStore, AzureAISearchVectorStoreConfig, AzureCosmosDBMongoDBSimilarityType, AzureCosmosDBMongoDBVectorStore, AzureCosmosDBNoSqlVectorStore, AzureQueryResultSearchBase, AzureQueryResultSearchDefault, AzureQueryResultSearchHybrid, AzureQueryResultSearchSemanticHybrid, AzureQueryResultSearchSparse, IndexManagement, MetadataIndexFieldType, SimpleCosmosDBReader };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Document, metadataDictToNode, BaseVectorStore, MetadataMode, nodeToMetadata, FilterOperator, FilterCondition, VectorStoreQueryMode } from '@vectorstores/core';
|
|
2
2
|
export * from './storage.js';
|
|
3
|
-
import { KnownVectorSearchAlgorithmKind, KnownAnalyzerNames, KnownSearchFieldDataType, KnownVectorSearchAlgorithmMetric, KnownVectorSearchCompressionKind, SearchClient, SearchIndexClient, AzureKeyCredential, IndexDocumentsBatch } from '@azure/search-documents';
|
|
4
3
|
import { DefaultAzureCredential, ManagedIdentityCredential } from '@azure/identity';
|
|
4
|
+
import { KnownVectorSearchAlgorithmKind, KnownAnalyzerNames, KnownSearchFieldDataType, KnownVectorSearchAlgorithmMetric, KnownVectorSearchCompressionKind, SearchClient, SearchIndexClient, AzureKeyCredential, IndexDocumentsBatch } from '@azure/search-documents';
|
|
5
5
|
import { consoleLogger, getEnv } from '@vectorstores/env';
|
|
6
6
|
import { MongoClient } from 'mongodb';
|
|
7
7
|
import { VectorEmbeddingDistanceFunction, VectorEmbeddingDataType, VectorIndexType, CosmosClient } from '@azure/cosmos';
|
|
@@ -787,7 +787,7 @@ console.log({ response });
|
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
789
|
#buildCredentials(options) {
|
|
790
|
-
let { credential
|
|
790
|
+
let { credential, key, endpoint, indexName } = options;
|
|
791
791
|
// validate and use credential
|
|
792
792
|
if (credential) {
|
|
793
793
|
// if credential are provided, ensure they are an instance of valid credential instances
|
|
@@ -1119,9 +1119,19 @@ console.log({ response });
|
|
|
1119
1119
|
// Execute the search and return the result
|
|
1120
1120
|
return await azureQueryResultSearch.search();
|
|
1121
1121
|
}
|
|
1122
|
+
async exists(refDocId) {
|
|
1123
|
+
const results = await this._searchClient.search("*", {
|
|
1124
|
+
filter: `ref_doc_id eq '${refDocId}'`,
|
|
1125
|
+
top: 1
|
|
1126
|
+
});
|
|
1127
|
+
for await (const _result of results.results){
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
return false;
|
|
1131
|
+
}
|
|
1122
1132
|
}
|
|
1123
1133
|
|
|
1124
|
-
var version = "0.1.
|
|
1134
|
+
var version = "0.1.4";
|
|
1125
1135
|
var pkg = {
|
|
1126
1136
|
version: version};
|
|
1127
1137
|
|
|
@@ -1204,13 +1214,14 @@ var pkg = {
|
|
|
1204
1214
|
return Object.values(insertResult.insertedIds).map((id)=>String(id));
|
|
1205
1215
|
}
|
|
1206
1216
|
/**
|
|
1207
|
-
*
|
|
1208
|
-
* @param
|
|
1217
|
+
* Deletes all nodes from the collection that belong to the given document.
|
|
1218
|
+
* @param refDocId Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
1219
|
+
* @param deleteOptions Additional delete options.
|
|
1209
1220
|
* @returns A promise that resolves when the documents have been removed.
|
|
1210
|
-
*/ async delete(
|
|
1221
|
+
*/ async delete(refDocId, deleteOptions) {
|
|
1211
1222
|
const collection = await this.ensureCollection();
|
|
1212
1223
|
await collection.deleteMany({
|
|
1213
|
-
|
|
1224
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
1214
1225
|
}, deleteOptions);
|
|
1215
1226
|
}
|
|
1216
1227
|
async query(query, options) {
|
|
@@ -1348,6 +1359,15 @@ var pkg = {
|
|
|
1348
1359
|
await collection.dropIndex(indexName);
|
|
1349
1360
|
}
|
|
1350
1361
|
}
|
|
1362
|
+
async exists(refDocId) {
|
|
1363
|
+
const collection = await this.ensureCollection();
|
|
1364
|
+
const count = await collection.countDocuments({
|
|
1365
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
1366
|
+
}, {
|
|
1367
|
+
limit: 1
|
|
1368
|
+
});
|
|
1369
|
+
return count > 0;
|
|
1370
|
+
}
|
|
1351
1371
|
}
|
|
1352
1372
|
|
|
1353
1373
|
const USER_AGENT_SUFFIX = "vectorstores-cdbnosql-vectorstore-javascript";
|
|
@@ -1530,14 +1550,28 @@ class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
1530
1550
|
return ids;
|
|
1531
1551
|
}
|
|
1532
1552
|
/**
|
|
1533
|
-
* Delete
|
|
1553
|
+
* Delete all nodes from the CosmosDB container that belong to the given document.
|
|
1534
1554
|
*
|
|
1535
|
-
* @param refDocId -
|
|
1536
|
-
* @param deleteOptions - Any options to pass to the
|
|
1555
|
+
* @param refDocId - Reference document ID - all nodes with this ref_doc_id will be deleted.
|
|
1556
|
+
* @param deleteOptions - Any options to pass to the delete operations.
|
|
1537
1557
|
* @returns Promise that resolves if the delete query did not throw an error.
|
|
1538
1558
|
*/ async delete(refDocId, deleteOptions) {
|
|
1539
1559
|
await this.initialize();
|
|
1540
|
-
|
|
1560
|
+
// Query all items with matching ref_doc_id
|
|
1561
|
+
const querySpec = {
|
|
1562
|
+
query: `SELECT c.id FROM c WHERE c.metadata.ref_doc_id = @refDocId`,
|
|
1563
|
+
parameters: [
|
|
1564
|
+
{
|
|
1565
|
+
name: "@refDocId",
|
|
1566
|
+
value: refDocId
|
|
1567
|
+
}
|
|
1568
|
+
]
|
|
1569
|
+
};
|
|
1570
|
+
const { resources: items } = await this.container.items.query(querySpec).fetchAll();
|
|
1571
|
+
// Delete each matching item
|
|
1572
|
+
for (const item of items){
|
|
1573
|
+
await this.container.item(item.id, item.id).delete(deleteOptions);
|
|
1574
|
+
}
|
|
1541
1575
|
}
|
|
1542
1576
|
/**
|
|
1543
1577
|
* Performs a vector similarity search query in the CosmosDB container.
|
|
@@ -1631,6 +1665,19 @@ class AzureCosmosDBNoSqlVectorStore extends BaseVectorStore {
|
|
|
1631
1665
|
});
|
|
1632
1666
|
this.container = container;
|
|
1633
1667
|
}
|
|
1668
|
+
async exists(refDocId) {
|
|
1669
|
+
await this.initialize();
|
|
1670
|
+
const { resources } = await this.container.items.query({
|
|
1671
|
+
query: `SELECT VALUE COUNT(1) FROM c WHERE c.metadata.ref_doc_id = @refDocId`,
|
|
1672
|
+
parameters: [
|
|
1673
|
+
{
|
|
1674
|
+
name: "@refDocId",
|
|
1675
|
+
value: refDocId
|
|
1676
|
+
}
|
|
1677
|
+
]
|
|
1678
|
+
}).fetchAll();
|
|
1679
|
+
return (resources[0] ?? 0) > 0;
|
|
1680
|
+
}
|
|
1634
1681
|
}
|
|
1635
1682
|
|
|
1636
1683
|
export { AzureAISearchVectorStore, AzureAISearchVectorStoreConfig, AzureCosmosDBMongoDBSimilarityType, AzureCosmosDBMongoDBVectorStore, AzureCosmosDBNoSqlVectorStore, AzureQueryResultSearchBase, AzureQueryResultSearchDefault, AzureQueryResultSearchHybrid, AzureQueryResultSearchSemanticHybrid, AzureQueryResultSearchSparse, IndexManagement, MetadataIndexFieldType, SimpleCosmosDBReader };
|