Skip to main content
`Ctrl`+`K`

# Milvus

This notebook shows how to use functionality related to the Milvus vector database.

To run, you should have a Milvus instance up and running: https://milvus.io/docs/install_standalone-docker.md

    from langchain.embeddings.openai import OpenAIEmbeddings
    from langchain.text_splitter import CharacterTextSplitter
    from langchain.vectorstores import Milvus
    from langchain.document_loaders import TextLoader

    from langchain.document_loaders import TextLoader
    loader = TextLoader('../../../state_of_the_union.txt')
    documents = loader.load()
    text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
    docs = text_splitter.split_documents(documents)

    embeddings = OpenAIEmbeddings()

    vector_db = Milvus.from_documents(
        docs,
        embeddings,
        connection_args={"host": "127.0.0.1", "port": "19530"},
    )

    docs = vector_db.similarity_search(query)

    docs[0]