spring-projects/spring-ai · warning · UnsupportedOperationException

Documents are ingested via data source sync, not direct add.

Error message

Documents are ingested via data source sync, not direct add.

What it means

BedrockKnowledgeBaseVectorStore.add(List<Document>) is deliberately unsupported because documents enter a Bedrock Knowledge Base through a configured data source and ingestion/sync jobs, not by direct vector writes. Calling add always throws an UnsupportedOperationException telling the developer to use data-source ingestion instead.

Source

Thrown at vector-stores/spring-ai-bedrock-knowledgebase-store/src/main/java/org/springframework/ai/vectorstore/bedrockknowledgebase/BedrockKnowledgeBaseVectorStore.java:103

		this.searchType = builder.searchType;
		this.rerankingModelArn = builder.rerankingModelArn;
		this.filterConverter = builder.filterConverter != null ? builder.filterConverter
				: new BedrockKnowledgeBaseFilterExpressionConverter();
	}

	/**
	 * Creates a new builder for BedrockKnowledgeBaseVectorStore.
	 * @param client the Bedrock Agent Runtime client
	 * @param knowledgeBaseId the ID of the Knowledge Base to query
	 * @return a new builder instance
	 */
	public static Builder builder(final BedrockAgentRuntimeClient client, final String knowledgeBaseId) {
		return new Builder(client, knowledgeBaseId);
	}

	@Override
	public void add(final List<Document> documents) {
		throw new UnsupportedOperationException("Documents are ingested via data source sync, not direct add.");
	}

	@Override
	public void delete(final List<String> idList) {
		throw new UnsupportedOperationException("Documents are managed via data source, not direct delete.");
	}

	@Override
	public void delete(final Filter.Expression filterExpression) {
		throw new UnsupportedOperationException("Documents are managed via data source, not direct delete.");
	}

	@Override
	public List<Document> similaritySearch(final SearchRequest request) {
		Assert.notNull(request, "SearchRequest must not be null");
		Assert.hasText(request.getQuery(), "Query must not be empty");

		int topK = request.getTopK() > 0 ? request.getTopK() : this.defaultTopK;

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Upload documents to the configured data source (typically S3) and trigger a knowledge base ingestion job via BedrockAgentClient.startIngestionJob instead of calling add
  2. Catch UnsupportedOperationException around add in generic write paths and route to the data-source ingestion flow for this store type
  3. Configure the knowledge base's data source properly (S3 bucket/prefix) so ingestion picks up new documents
  4. Guard shared code by checking store type before calling add

Example fix

// before
vectorStore.add(List.of(new Document("text"))); // UnsupportedOperationException
// after
s3Client.putObject(b -> b.bucket(bucket).key("doc1.txt"), RequestBody.fromString("text"));
bedrockAgentClient.startIngestionJob(b -> b.knowledgeBaseId(kbId).dataSourceId(dsId));
Defensive patterns

Strategy: try-catch

Validate before calling

if (store instanceof BedrockKnowledgeBaseVectorStore) { throw new IllegalStateException("Use data source ingestion for Bedrock KB; add() is unsupported"); }

Type guard

boolean supportsAdd(VectorStore store) { return !(store instanceof BedrockKnowledgeBaseVectorStore); }

Try / catch

try { store.add(documents); } catch (UnsupportedOperationException e) { uploadToS3AndStartIngestion(documents); }

Prevention

When it happens

Trigger: Calling store.add(documents) directly, using a generic ingestion pipeline that calls VectorStore.add for any store implementation, or swapping a different VectorStore (e.g. PgVector) for BedrockKnowledgeBaseVectorStore in existing embedding-write code.

Common situations: Reusing ETL/embedding code written for other vector stores; attempting to add freshly embedded documents without an S3 data source; demo/prototype code that assumes all VectorStore implementations support writes.

Related errors


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