[Bug]: VDBStoreBase#delete key semantics differ across stores (chunk id vs doc_id), so no single key works
Bug description
VDBStoreBase#delete(String id) is documented as "@param id the document ID (UUID string) to delete" (VDBStoreBase.java#L68-L77). But the five built-in stores interpret that argument in two incompatible ways:
| Store | Deletes by | Effect |
|---|---|---|
InMemoryStore |
Document.getId() (chunk primary key) |
one chunk |
ElasticsearchStore |
Document.getId() (index _id) |
one chunk |
QdrantStore |
Document.getId(), parsed with UUID.fromString |
one chunk |
MilvusStore |
doc_id in ["…"] filter (#L712-L725) |
every chunk of the source document |
PgVectorStore |
WHERE doc_id = ? (#L775-L785) |
every chunk of the source document |
No single key works across stores, so code written against the interface silently does the wrong thing when the backend is swapped:
- Passing
Document.getId()(what the Javadoc says): works on InMemory, Elasticsearch and Qdrant. On Milvus and PgVector it matches nothing and returnsfalse, and the vectors stay searchable. - Passing
DocumentMetadata.getDocId(): works on Milvus and PgVector (and removes the whole document). On Qdrant, readers such asPDFReader/TikaReaderproduce a SHA-256 hexdocId, not a UUID, soUUID.fromStringthrows and the call fails withVectorStoreException. On InMemory and Elasticsearch it matches nothing and returnsfalse.
Two smaller inconsistencies in the same method:
- The
VDBStoreBase#deleteJavadoc says "Default implementation throws UnsupportedOperationException", but the method is abstract and has no default. - The meaning of the return value also differs. Milvus and PgVector return "deleted count > 0".
QdrantStorereturnsstatus == Completed, which reflects the operation status rather than whether a point existed (#L633-L639).
Unchanged between 2.0.4 and current main 16cb024.
Suggested fix
Make the contract explicit and split the two operations, since both are useful:
delete(String id)means delete one chunk byDocument.getId(), consistently in all five stores. Milvus and PgVector would filter on their primary-key column (id) instead ofdoc_id.- Add
deleteByDocId(String docId)(a default method that throwsUnsupportedOperationException) to remove all chunks of a source document. Implement it natively in Milvus, PgVector and Elasticsearch, and with a payload filter in Qdrant. - Specify the return value as "at least one record was removed", and fix the stale "default implementation" sentence.
Changing Milvus and PgVector's delete is a behaviour change for anyone currently relying on "delete by doc id" there. The release note can point those users to deleteByDocId.
Context
Our knowledge-base feature (document-level delete) runs on InMemory in tests and Milvus in production. Today we work around this by calling delete with both every chunk id and the doc id, so that whichever store is behind the interface hits one of them. I'm willing to send the PR, including a shared contract test that all five stores run.
I'll take this one.
Plan, as proposed above:
delete(String id)deletes a single chunk byDocument.getId()in all five stores. Milvus and PgVector switch from thedoc_idfilter to their primary-key column.- New
deleteByDocId(String docId)deletes every chunk of a source document. It's a default method onVDBStoreBasethat throwsUnsupportedOperationException, and it's implemented in all five built-in stores. - The return value is specified as "at least one record was removed" everywhere, including Qdrant. The stale "default implementation" Javadoc sentence is fixed.
- A shared contract test runs against every store, so the semantics can't drift again.
The one thing I'd like a maintainer to confirm is the behaviour change for Milvus and PgVector: their delete would stop removing the whole document. If you'd rather avoid that in a minor release, I can keep their current behaviour and only add deleteByDocId, deprecate the ambiguous delete, and document the per-store difference. I'll start with the first option unless someone prefers the second.