Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

milvus replica number factorization #15442

Closed
rere950303 opened this issue Jan 3, 2024 · 1 comment · Fixed by #15447
Closed

milvus replica number factorization #15442

rere950303 opened this issue Jan 3, 2024 · 1 comment · Fixed by #15447
Labels
🤖:improvement Medium size change to existing code to handle new use-cases Ɑ: vector store Related to vector store module

Comments

@rere950303
Copy link
Contributor

Feature request

If in-memory replica is increased in milvus, replica_number should be set when loading collection in langchain, but the default setting is 1 and cannot be changed.

pymilvus.exceptions.MilvusException: <MilvusException: (code=1100, message=failed to load collection: can't change the replica number for loaded collection: expected=3, actual=1: invalid parameter)>

When creating the Milvus object, please change it so that replica_number can be passed over to the argument

Motivation

There is no way to change replica_number in langchain when in-memory replica is increased in milvus.

Your contribution

  • milvus.py
    def __init__(
        self,
        embedding_function: Embeddings,
        collection_name: str = "LangChainCollection",
        connection_args: Optional[dict[str, Any]] = None,
        consistency_level: str = "Session",
        index_params: Optional[dict] = None,
        search_params: Optional[dict] = None,
        drop_old: Optional[bool] = False,
        *,
        primary_field: str = "pk",
        text_field: str = "text",
        vector_field: str = "vector",
        replica_number : int = 1 // added factor
    ):
        """Initialize the Milvus vector store."""
        try:
            from pymilvus import Collection, utility
        except ImportError:
            raise ValueError(
                "Could not import pymilvus python package. "
                "Please install it with `pip install pymilvus`."
            )

        # Default search params when one is not provided.
        self.default_search_params = {
            "IVF_FLAT": {"metric_type": "L2", "params": {"nprobe": 10}},
            "IVF_SQ8": {"metric_type": "L2", "params": {"nprobe": 10}},
            "IVF_PQ": {"metric_type": "L2", "params": {"nprobe": 10}},
            "HNSW": {"metric_type": "L2", "params": {"ef": 10}},
            "RHNSW_FLAT": {"metric_type": "L2", "params": {"ef": 10}},
            "RHNSW_SQ": {"metric_type": "L2", "params": {"ef": 10}},
            "RHNSW_PQ": {"metric_type": "L2", "params": {"ef": 10}},
            "IVF_HNSW": {"metric_type": "L2", "params": {"nprobe": 10, "ef": 10}},
            "ANNOY": {"metric_type": "L2", "params": {"search_k": 10}},
            "AUTOINDEX": {"metric_type": "L2", "params": {}},
        }

        self.embedding_func = embedding_function
        self.collection_name = collection_name
        self.index_params = index_params
        self.search_params = search_params
        self.consistency_level = consistency_level

        # In order for a collection to be compatible, pk needs to be auto'id and int
        self._primary_field = primary_field
        # In order for compatibility, the text field will need to be called "text"
        self._text_field = text_field
        # In order for compatibility, the vector field needs to be called "vector"
        self._vector_field = vector_field
        self.fields: list[str] = []
        # Create the connection to the server
        if connection_args is None:
            connection_args = DEFAULT_MILVUS_CONNECTION
        self.alias = self._create_connection_alias(connection_args)
        self.col: Optional[Collection] = None

        # Grab the existing collection if it exists
        if utility.has_collection(self.collection_name, using=self.alias):
            self.col = Collection(
                self.collection_name,
                using=self.alias,
            )
        # If need to drop old, drop it
        if drop_old and isinstance(self.col, Collection):
            self.col.drop()
            self.col = None

        # Initialize the vector store
        self._init(replica_number=replica_number)

Please let me take the replica_number as an argument in the same way as above

Copy link

dosubot bot commented Jan 3, 2024

🤖

Thank you for your interest in contributing to LangChain! It's great to see your proposed solution for adding the replica_number as an argument in the __init__ method of milvus.py. Your contribution will definitely enhance the flexibility and usability of LangChain for users working with Milvus.

I encourage you to go ahead and create a pull request with your proposed changes. The maintainers will review it and provide feedback. Your contribution is valuable, and it's great to see the community coming together to improve LangChain. Keep up the good work!


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added Ɑ: vector store Related to vector store module 🤖:improvement Medium size change to existing code to handle new use-cases labels Jan 3, 2024
hwchase17 pushed a commit that referenced this issue Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases Ɑ: vector store Related to vector store module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant