Skip to content

Commit

Permalink
refactor: use a single param for delete
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Apr 29, 2024
1 parent 1a0fbaa commit 4055993
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions libs/langchain-community/src/vectorstores/azure_cosmosdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export type AzureCosmosDBIndexOptions = {
readonly similarity?: AzureCosmosDBSimilarityType;
};

/** Azure Cosmos DB Delete Parameters. */
export type AzureCosmosDBDeleteParams = {
/** List of IDs for the documents to be removed. */
readonly ids?: string | string[];
/** MongoDB filter object or list of IDs for the documents to be removed. */
readonly filter?: Filter<MongoDBDocument>;
};

/**
* Configuration options for the `AzureCosmosDBVectorStore` constructor.
*/
Expand Down Expand Up @@ -234,16 +242,13 @@ export class AzureCosmosDBVectorStore extends VectorStore {
/**
* Removes specified documents from the AzureCosmosDBVectorStore.
* If no IDs or filter are specified, all documents will be removed.
* @param ids A list of IDs for the documents to be removed.
* @param filter A MongoDB filter object or list of IDs for the documents to be removed.
* @param params Parameters for the delete operation.
* @returns A promise that resolves when the documents have been removed.
*/
async delete(
ids?: string | string[],
filter?: Filter<MongoDBDocument>
): Promise<void> {
async delete(params: AzureCosmosDBDeleteParams = {}): Promise<void> {
await this.initPromise;

const { ids, filter } = params;
const idsArray = Array.isArray(ids) ? ids : [ids];
const deleteIds = ids && idsArray.length > 0 ? idsArray : undefined;
let deleteFilter = filter ?? {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe.skip("AzureCosmosDBVectorStore", () => {
]);

// Delete document matching specified ids
await vectorStore.delete(ids.slice(0, 1));
await vectorStore.delete({ ids: ids.slice(0, 1) });

const results = await vectorStore.similaritySearch("politics", 10);

Expand Down Expand Up @@ -214,7 +214,7 @@ describe.skip("AzureCosmosDBVectorStore", () => {
]);

// Delete document matching the filter
await vectorStore.delete(undefined, { a: 1 });
await vectorStore.delete({ filter: { a: 1 } });

const results = await vectorStore.similaritySearch("politics", 10);

Expand Down

0 comments on commit 4055993

Please sign in to comment.