Skip to content

Commit

Permalink
feat(qdrant): Add a Function to Delete Points in Qdrant (#7176)
Browse files Browse the repository at this point in the history
Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
  • Loading branch information
felipediel and jacoblee93 authored Nov 12, 2024
1 parent c5f336b commit 8477618
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions libs/langchain-qdrant/src/vectorstores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export type QdrantAddDocumentOptions = {
customPayload: Record<string, any>[];
};

/**
* Type that defines the parameters for the delete operation in the
* QdrantStore class. It includes ids, filter and shard key.
*/
export type QdrantDeleteParams =
| { ids: string[]; shardKey?: string; filter?: never }
| { filter: object; shardKey?: string; ids?: never };

export type QdrantFilter = QdrantSchemas["Filter"];

export type QdrantCondition = QdrantSchemas["FieldCondition"];
Expand Down Expand Up @@ -174,6 +182,37 @@ export class QdrantVectorStore extends VectorStore {
}
}

/**
* Method that deletes points from the Qdrant database.
* @param params Parameters for the delete operation.
* @returns Promise that resolves when the delete operation is complete.
*/
async delete(params: QdrantDeleteParams): Promise<void> {
const { ids, filter, shardKey } = params;

if (ids) {
const batchSize = 1000;
for (let i = 0; i < ids.length; i += batchSize) {
const batchIds = ids.slice(i, i + batchSize);
await this.client.delete(this.collectionName, {
wait: true,
ordering: "weak",
points: batchIds,
shard_key: shardKey,
});
}
} else if (filter) {
await this.client.delete(this.collectionName, {
wait: true,
ordering: "weak",
filter,
shard_key: shardKey,
});
} else {
throw new Error("Either ids or filter must be provided.");
}
}

/**
* Method to search for vectors in the Qdrant database that are similar to
* a given query vector. The search results include the score and payload
Expand Down

0 comments on commit 8477618

Please sign in to comment.