spring-projects/spring-ai · warning

Failed to delete all documents

Error message

Failed to delete all documents

What it means

TypesenseVectorStore.doDelete(List<String>) deletes documents by query and compares num_deleted with idList.size(); if fewer were deleted it warns 'Failed to delete all documents'. Typesense deletes by a filter query built from the ids, so a mismatch means some ids were not found or the delete filter didn't match. Exceptions are logged at ERROR and swallowed.

Source

Thrown at vector-stores/spring-ai-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java:191

	@Override
	public void doDelete(List<String> idList) {
		DeleteDocumentsParameters deleteDocumentsParameters = new DeleteDocumentsParameters();
		// Typesense filter_by for the id field expects bare string values, not quoted
		// literals — e.g. id: [id1,id2]. Typesense document IDs are restricted to
		// URL-safe characters (no commas, brackets, or quotes), so raw string joining
		// is safe here. The operator is `: ` (not `:=`) per the Typesense recommendation
		// for multi-value id filters.
		deleteDocumentsParameters.filterBy(DOC_ID_FIELD_NAME + ": [" + String.join(",", idList) + "]");

		try {
			int deletedDocs = (Integer) this.client.collections(this.collectionName)
				.documents()
				.delete(deleteDocumentsParameters)
				.getOrDefault("num_deleted", 0);

			if (deletedDocs < idList.size()) {
				logger.warn("Failed to delete all documents");
			}
		}
		catch (Exception e) {
			logger.error("Failed to delete documents", e);
		}
	}

	@Override
	protected void doDelete(Filter.Expression filterExpression) {
		Assert.notNull(filterExpression, "Filter expression must not be null");

		try {
			String filterStr = this.filterExpressionConverter.convertExpression(filterExpression);
			DeleteDocumentsParameters deleteDocumentsParameters = new DeleteDocumentsParameters();
			deleteDocumentsParameters.filterBy(filterStr);

			Map<String, Object> response = this.client.collections(this.collectionName)
				.documents()

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Verify the ids exist in the Typesense collection (documents().search by id) before deleting
  2. Check the collectionName configuration matches where documents were written
  3. Inspect the logged exception (if any) for connectivity/auth problems with the Typesense server
  4. Escape/normalize ids used in the delete filter query

Example fix

// before
typesenseVectorStore.delete(ids); // partial deletes only warned

// after
List<Document> existing = typesenseVectorStore.similaritySearchByIds(ids); // or verify per id
typesenseVectorStore.delete(ids);
logger.info("deleted request size=" + ids.size());
Defensive patterns

Strategy: validation

Validate before calling

// confirm ids exist in Typesense before delete
// use the Typesense client to retrieve each document and skip missing ids

Try / catch

try {
    typesenseVectorStore.delete(ids);
} catch (Exception e) {
    logger.error("Typesense delete failed (check ERROR log 'Failed to delete documents')", e);
}

Prevention

When it happens

Trigger: vectorStore.delete(List.of(id)) where Typesense's documents().delete returns num_deleted < id count — ids absent, already deleted, or not matching the generated filter; any thrown exception also logs 'Failed to delete documents'.

Common situations: Deleting stale ids after a re-index; collectionName mismatch; Typesense server connectivity issues (caught exception path); special characters in ids breaking the delete filter.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/37e43b4c4133c720. Report an issue: GitHub.