Allowing custom text field name for Milvus (#7789)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67c4ca7941569..4e6daff48ba4e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
 ### New Features
 - Added native support for `HuggingFaceEmbedding`, `InstructorEmbedding`, and `OptimumEmbedding` (#7795)
 - Added metadata filtering and hybrid search to MyScale vector store (#7780)
+- Allowing custom text field name for Milvus (#7790)
 - Add support for `vector_store_query_mode` to `VectorIndexAutoRetriever` (#7797)
 
 ### Bug Fixes / Nits
diff --git a/llama_index/vector_stores/milvus.py b/llama_index/vector_stores/milvus.py
index 69eb0e0011e15..528bdf7c8c4c7 100644
--- a/llama_index/vector_stores/milvus.py
+++ b/llama_index/vector_stores/milvus.py
@@ -6,9 +6,7 @@
 import logging
 from typing import Any, List, Optional
 
-from llama_index.schema import (
-    BaseNode,
-)
+from llama_index.schema import BaseNode, TextNode
 from llama_index.vector_stores.types import (
     MetadataFilters,
     VectorStore,
@@ -67,6 +65,8 @@ class MilvusVectorStore(VectorStore):
             created collection. Defaults to "Session".
         overwrite (bool, optional): Whether to overwrite existing collection with same
             name. Defaults to False.
+        text_key (str, optional): What key text is stored in in the passed collection.
+            Used when bringing your own collection. Defaults to None.
 
     Raises:
         ImportError: Unable to import `pymilvus`.
@@ -91,6 +91,7 @@ def __init__(
         similarity_metric: str = "IP",
         consistency_level: str = "Strong",
         overwrite: bool = False,
+        text_key: Optional[str] = None,
         **kwargs: Any,
     ) -> None:
         """Init params."""
@@ -110,6 +111,7 @@ def __init__(
         self.doc_id_field = doc_id_field
         self.consistency_level = consistency_level
         self.overwrite = overwrite
+        self.text_key = text_key
 
         # Select the similarity metric
         if similarity_metric.lower() in ("ip"):
@@ -270,9 +272,21 @@ def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResul
 
         # Parse the results
         for hit in res[0]:
-            node = metadata_dict_to_node(
-                {"_node_content": hit["entity"].get("_node_content", None)}
-            )
+            if not self.text_key:
+                node = metadata_dict_to_node(
+                    {"_node_content": hit["entity"].get("_node_content", None)}
+                )
+            else:
+                try:
+                    text = hit["entity"].get(self.text_key)
+                except Exception:
+                    raise ValueError(
+                        "The passed in text_key value does not exist "
+                        "in the retrieved entity."
+                    )
+                node = TextNode(
+                    text=text,
+                )
             nodes.append(node)
             similarities.append(hit["distance"])
             ids.append(hit["id"])

# Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # 7789

## Type of Change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

- [ ] Added new unit/integration tests
- [ ] Added new notebook (that tests end-to-end)
- [x] I stared at the code and made sure it makes sense

# Suggested Checklist:

- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
