spring-projects / spring-projects/spring-ai
[Qdrant] Hardcoded "doc_content" field name in QdrantVectorStore causes IllegalArgumentException when retrieving documents
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Description
I am using Spring AI (v1.1.2) with Qdrant for RAG implementation. In my Qdrant collection, the document text is stored in the standard content field within the payload.
However, when performing a similaritySearch, the application throws an IllegalArgumentException. Upon debugging, it appears that QdrantVectorStore expects the payload key to be "doc_content" instead of "content". Since the key does not match, the content is retrieved as null, causing the validation in the Document constructor to fail.
It seems there is no easy way to configure this field name via application.yml properties in the current auto-configuration.
Environment
Spring AI Version: 1.1.2
Spring Boot Version: 3.4.2 (Please adjust if different)
Java Version: 21
Steps to Reproduce
Insert a vector into Qdrant with a payload structure like:
{
"payload": {
"content": "This is a test document",
"some_metadata": "value"
}
}
Execute a similarity search using QdrantVectorStore.
Java
List results = vectorStore.similaritySearch("test");
The application crashes with the exception below.
Actual Behavior / Stack Trace
The toDocument method fails to map the payload content to the Document object.
Plaintext
java.lang.RuntimeException: java.lang.IllegalArgumentException: exactly one of text or media must be specified
at org.springframework.ai.vectorstore.qdrant.QdrantVectorStore.toDocument(QdrantVectorStore.java:288)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
...
Caused by: java.lang.IllegalArgumentException: exactly one of text or media must be specified
at org.springframework.util.Assert.isTrue(Assert.java:116)
at org.springframework.ai.document.Document.(Document.java:156)
at org.springframework.ai.document.Document$Builder.build(Document.java:384)
at org.springframework.ai.vectorstore.qdrant.QdrantVectorStore.toDocument(QdrantVectorStore.java:285)
Root Cause Analysis
By debugging the QdrantVectorStore#toDocument method, I observed the following logic:
Java
// The key is hardcoded or defaults to "doc_content"
String content = (String) metadata.remove("doc_content");
Since my database uses "content", the content variable becomes null, triggering the assertion error in the Document builder.
Suggested Fix
Make the content field name configurable: Expose a property (e.g., spring.ai.vectorstore.qdrant.content-field-name) in the QdrantVectorStoreAutoConfiguration so users can specify their payload key (e.g., "content", "text", "page_content").
Update Default: Consider changing the default back to "content" as it is a common standard, or implement a fallback mechanism.
Currently, I have to workaround this by creating a custom class to shadow QdrantVectorStore or manually defining the Bean with a modified constructor (if available).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect QdrantVectorStore#toDocument, especially the hardcoded "doc_content" lookup, and then review QdrantVectorStoreAutoConfiguration for the available configuration properties. Reproduce the similaritySearch failure with a payload using "content". Done means the payload content field can be configured or handled as agreed, and document retrieval no longer fails with the validation exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100