agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]: VDBStoreBase#delete key semantics differ across stores (chunk id vs doc_id), so no single key works

Open littlebird69 opened this issue 1 month ago • 1 comments

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 returns false, and the vectors stay searchable.
  • Passing DocumentMetadata.getDocId(): works on Milvus and PgVector (and removes the whole document). On Qdrant, readers such as PDFReader / TikaReader produce a SHA-256 hex docId, not a UUID, so UUID.fromString throws and the call fails with VectorStoreException. On InMemory and Elasticsearch it matches nothing and returns false.

Two smaller inconsistencies in the same method:

  • The VDBStoreBase#delete Javadoc 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". QdrantStore returns status == 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 by Document.getId(), consistently in all five stores. Milvus and PgVector would filter on their primary-key column (id) instead of doc_id.
  • Add deleteByDocId(String docId) (a default method that throws UnsupportedOperationException) 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.

littlebird69 avatar Oct 27 '26 02:10 littlebird69

I'll take this one.

Plan, as proposed above:

  • delete(String id) deletes a single chunk by Document.getId() in all five stores. Milvus and PgVector switch from the doc_id filter to their primary-key column.
  • New deleteByDocId(String docId) deletes every chunk of a source document. It's a default method on VDBStoreBase that throws UnsupportedOperationException, 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.

littlebird69 avatar Oct 27 '26 02:10 littlebird69