From 2254bb5df37daffd10b25a75f8fae378ef12533b Mon Sep 17 00:00:00 2001
From: "Chandrashekar V.T" <57014454+chandrashekarvt@users.noreply.github.com>
Date: Fri, 5 Apr 2024 21:31:11 +0530
Subject: [PATCH] Bug fix - Similarity metric is always IP for
 MilvusVectorStore (#12611)

---
 .../llama_index/vector_stores/milvus/base.py        | 13 ++++++++++---
 .../llama-index-vector-stores-milvus/pyproject.toml |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py b/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py
index 0c3cb197aa..433b110e2a 100644
--- a/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py
+++ b/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py
@@ -151,8 +151,15 @@ class MilvusVectorStore(BasePydanticVectorStore):
         )
 
         # Select the similarity metric
-        similarity_metrics_map = {"ip": "IP", "l2": "L2", "euclidean": "L2"}
-        similarity_metric = similarity_metrics_map.get(similarity_metric.lower(), "L2")
+        similarity_metrics_map = {
+            "ip": "IP",
+            "l2": "L2",
+            "euclidean": "L2",
+            "cosine": "COSINE",
+        }
+        self.similarity_metric = similarity_metrics_map.get(
+            similarity_metric.lower(), "L2"
+        )
 
         # Connect to Milvus instance
         self._milvusclient = MilvusClient(
@@ -174,7 +181,7 @@ class MilvusVectorStore(BasePydanticVectorStore):
                 primary_field_name=MILVUS_ID_FIELD,
                 vector_field_name=embedding_field,
                 id_type="string",
-                metric_type=similarity_metric,
+                metric_type=self.similarity_metric,
                 max_length=65_535,
                 consistency_level=consistency_level,
             )
diff --git a/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/pyproject.toml b/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/pyproject.toml
index 79957eb2c7..e45be5c7a4 100644
--- a/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/pyproject.toml
+++ b/llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/pyproject.toml
@@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
 license = "MIT"
 name = "llama-index-vector-stores-milvus"
 readme = "README.md"
-version = "0.1.6"
+version = "0.1.7"
 
 [tool.poetry.dependencies]
 python = ">=3.8.1,<4.0"
-- 
GitLab