# MilvusRetriever

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/retrievers/milvus/MilvusRetriever)

Milvus API retriever.

See detailed instructions here: https://python.langchain.com/docs/integrations/retrievers/milvus_hybrid_search/

## Signature

```python
MilvusRetriever()
```

## Description

**Setup:**

Install ``langchain-milvus`` and other dependencies:

.. code-block:: bash

    pip install -U pymilvus[model] langchain-milvus

**Key init args:**

collection: Milvus Collection

**Instantiate:**

.. code-block:: python

retriever = MilvusCollectionHybridSearchRetriever(collection=collection)

**Usage:**

.. code-block:: python

    query = "What are the story about ventures?"

    retriever.invoke(query)

.. code-block:: none

    [Document(page_content="In 'The Lost Expedition' by Caspian Grey...", metadata={'doc_id': '449281835035545843'}),
    Document(page_content="In 'The Phantom Pilgrim' by Rowan Welles...", metadata={'doc_id': '449281835035545845'}),
    Document(page_content="In 'The Dreamwalker's Journey' by Lyra Snow..", metadata={'doc_id': '449281835035545846'})]

**Use within a chain:**

.. code-block:: python

    from langchain_core.output_parsers import StrOutputParser
    from langchain_core.prompts import ChatPromptTemplate
    from langchain_core.runnables import RunnablePassthrough
    from langchain_openai import ChatOpenAI

    prompt = ChatPromptTemplate.from_template(
        """Answer the question based only on the context provided.

    Context: {context}

    Question: {question}"""
    )

    llm = ChatOpenAI(model="gpt-3.5-turbo-0125")

    def format_docs(docs):
        return "\n\n".join(doc.page_content for doc in docs)

    chain = (
        {"context": retriever | format_docs, "question": RunnablePassthrough()}
        | prompt
        | llm
        | StrOutputParser()
    )

    chain.invoke("What novels has Lila written and what are their contents?")

.. code-block:: none

     "Lila Rose has written 'The Memory Thief,' which follows a charismatic thief..."

## Extends

- `BaseRetriever`

## Properties

- `embedding_function`
- `collection_name`
- `collection_properties`
- `connection_args`
- `consistency_level`
- `search_params`
- `store`
- `retriever`

## Methods

- [`create_retriever()`](https://reference.langchain.com/python/langchain-community/retrievers/milvus/MilvusRetriever/create_retriever)
- [`add_texts()`](https://reference.langchain.com/python/langchain-community/retrievers/milvus/MilvusRetriever/add_texts)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/d5ea8358933260ad48dd31f7f8076555c7b4885a/libs/community/langchain_community/retrievers/milvus.py#L17)