Skip to content

fix(milvus): make metric type configurable to prevent mismatch errors#6199

Closed
octo-patch wants to merge 1 commit intoFlowiseAI:mainfrom
octo-patch:fix/issue-6033-milvus-configurable-metric-type
Closed

fix(milvus): make metric type configurable to prevent mismatch errors#6199
octo-patch wants to merge 1 commit intoFlowiseAI:mainfrom
octo-patch:fix/issue-6033-milvus-configurable-metric-type

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #6033

Problem

The Milvus node hardcoded MetricType.L2 when creating a new index in MilvusUpsert.addVectors(). Users with collections configured to use COSINE or IP metric types encountered metric type mismatch errors during vector insertion, because the index was always created with L2 regardless of the collection's actual metric type.

Solution

  • Added a Metric Type dropdown input parameter to the Milvus node (under Additional Parameters) with options: L2 (default, backward-compatible), COSINE, and IP
  • The selected metric type is passed via indexCreateParams in MilvusLibArgs during upsert
  • MilvusUpsert.addVectors() now uses this.indexCreateParams?.metric_type ?? MetricType.L2 instead of the hardcoded MetricType.L2, ensuring the index is created with the correct metric type
  • Bumped node version from 2.1 to 2.2

Testing

  • Users can now select the appropriate metric type matching their Milvus collection configuration
  • Defaults to L2 for full backward compatibility with existing flows
  • The similarity search already read vectorStore.indexCreateParams.metric_type correctly — this fix aligns upsert to do the same

…fixes FlowiseAI#6033)

Previously the metric type was hardcoded to L2 when creating a new Milvus
index in addVectors(), causing metric type mismatch errors for collections
using COSINE or IP. Added a configurable Metric Type input parameter (L2,
COSINE, IP) and wired it through indexCreateParams so upsert operations
use the correct metric type.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Milvus vector store component to version 2.2 and introduces a configurable 'Metric Type' input for similarity searches, supporting L2, COSINE, and IP metrics. While the metric type is correctly implemented for upsert operations, it is currently missing from the 'init' method. This omission will cause retrieval and search operations to ignore the user-selected metric, potentially leading to incorrect results or runtime errors when accessing index parameters.

},
{
label: 'Metric Type',
name: 'milvusMetricType',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new milvusMetricType input is correctly utilized in the upsert method, but it is missing from the init method (lines 266-347). This is a significant oversight because when the node is used for retrieval (the retriever output) or to connect to an existing collection, it will ignore the user-selected metric type.

This leads to two issues:

  1. Potential Crash: similaritySearchVectorWithScore (line 387) and the score normalization logic (line 420) both access vectorStore.indexCreateParams.metric_type. If indexCreateParams is not provided in init, this may throw an error or result in incorrect search behavior.
  2. Metric Mismatch: Search operations will use the default metric type instead of the one configured by the user, which is the exact problem this PR aims to solve for upserts.

The init method needs to extract milvusMetricType and include it in milVusArgs.indexCreateParams similarly to the upsert implementation.

References
  1. When a feature requires a specific configuration, it is preferable to throw an error if the configuration is missing rather than silently falling back to a different implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Milvus metric type is not configurable

2 participants