MilvusException: (code=1100, message=failed to create query plan: cannot parse expression: metadata["document_id"] #12424

Closed
opened 2026-02-21 19:07:20 -05:00 by yindo · 3 comments
Owner

Originally created by @309299817 on GitHub (Apr 1, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.1.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

1、当知识库检索中设置了元数据过滤
2、我的向量库选择的是milvus
3、程序就会报错:ValueError: <MilvusException: (code=1100, message=failed to create query plan: cannot parse expression: metadata["document_id"] in ('0a07e429-c172-4a48-bcc9-a4a98cbb7776', 'b93d050a-3021-451a-9300-7864cf05aee2'), error: line 1:66 mismatched input ',' expecting ')': invalid parameter)>

✔️ Expected Behavior

Modify the source code of line 181 in retrievval_Service. py

vector = Vector(dataset=dataset)

构建过滤条件

filter_conditions = {"group_id": [dataset.id]}
if document_ids_filter:
filter_conditions["document_id"] = document_ids_filter

documents = vector.search_by_vector(
query,
search_type="similarity_score_threshold",
top_k=top_k,
score_threshold=score_threshold,
filter=filter_conditions,
)

documents = vector.search_by_vector(

query,

search_type="similarity_score_threshold",

top_k=top_k,

score_threshold=score_threshold,

filter={"group_id": [dataset.id]},

document_ids_filter=document_ids_filter,

)

Actual Behavior

No response

Originally created by @309299817 on GitHub (Apr 1, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.1.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1、当知识库检索中设置了元数据过滤 2、我的向量库选择的是milvus 3、程序就会报错:ValueError: <MilvusException: (code=1100, message=failed to create query plan: cannot parse expression: metadata["document_id"] in ('0a07e429-c172-4a48-bcc9-a4a98cbb7776', 'b93d050a-3021-451a-9300-7864cf05aee2'), error: line 1:66 mismatched input ',' expecting ')': invalid parameter)> ### ✔️ Expected Behavior Modify the source code of line 181 in retrievval_Service. py vector = Vector(dataset=dataset) # 构建过滤条件 filter_conditions = {"group_id": [dataset.id]} if document_ids_filter: filter_conditions["document_id"] = document_ids_filter documents = vector.search_by_vector( query, search_type="similarity_score_threshold", top_k=top_k, score_threshold=score_threshold, filter=filter_conditions, ) # documents = vector.search_by_vector( # query, # search_type="similarity_score_threshold", # top_k=top_k, # score_threshold=score_threshold, # filter={"group_id": [dataset.id]}, # document_ids_filter=document_ids_filter, # ) ### ❌ Actual Behavior _No response_
yindo added the 👻 feat:rag label 2026-02-21 19:07:20 -05:00
yindo closed this issue 2026-02-21 19:07:20 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Apr 1, 2025):

Hello, @309299817! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve the issue you're facing.

To resolve the MilvusException error with code 1100 related to the query plan and metadata["document_id"], you should correct the syntax of your metadata filter. Use square brackets instead of parentheses for filtering document IDs in Milvus metadata. The correct syntax is:

filter = f'metadata["document_id"] in [{document_ids}]'

Ensure that document_ids is a comma-separated string of quoted IDs [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Apr 1, 2025): <!-- Greeting --> Hello, @309299817! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve the issue you're facing. <!-- Answer --> To resolve the `MilvusException` error with code 1100 related to the query plan and `metadata["document_id"]`, you should correct the syntax of your metadata filter. Use square brackets instead of parentheses for filtering document IDs in Milvus metadata. The correct syntax is: ```python filter = f'metadata["document_id"] in [{document_ids}]' ``` Ensure that `document_ids` is a comma-separated string of quoted IDs <sup>[[1]](https://github.com/langgenius/dify/issues/16957)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/256892cc-58ae-496d-be7b-95b78d381a0c?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/256892cc-58ae-496d-be7b-95b78d381a0c?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/256892cc-58ae-496d-be7b-95b78d381a0c?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/256892cc-58ae-496d-be7b-95b78d381a0c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/256892cc-58ae-496d-be7b-95b78d381a0c?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/256892cc-58ae-496d-be7b-95b78d381a0c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/256892cc-58ae-496d-be7b-95b78d381a0c?feedback_type=other)</sup>
Author
Owner

@309299817 commented on GitHub (Apr 1, 2025):

Yes, modify the 235 line code of milvus_vector. py to change

filter=f 'metadata ["document_id"] in ({document_ids})' 

to

 filter=f 'metadata ["document_id"] in [{document_ids}]'
@309299817 commented on GitHub (Apr 1, 2025): Yes, modify the 235 line code of milvus_vector. py to change ~~~ filter=f 'metadata ["document_id"] in ({document_ids})' ~~~ to ~~~ filter=f 'metadata ["document_id"] in [{document_ids}]' ~~~
Author
Owner

@JohnJyong commented on GitHub (Apr 2, 2025):

it has already fixed by https://github.com/langgenius/dify/pull/16725 , @309299817

@JohnJyong commented on GitHub (Apr 2, 2025): it has already fixed by https://github.com/langgenius/dify/pull/16725 , @309299817
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12424