Skip to content

Support scalar field indexing for milvus collection creation #24343

@rgupta2508

Description

@rgupta2508

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

def _create_index(self) -> None:
    """Create a index on the collection"""
    from pymilvus import Collection, MilvusException

    if isinstance(self.col, Collection) and self._get_index() is None:
        try:
            # If no index params, use a default HNSW based one
            if self.index_params is None:
                self.index_params = {
                    "metric_type": "L2",
                    "index_type": "HNSW",
                    "params": {"M": 8, "efConstruction": 64},
                }

            try:
                self.col.create_index(
                    self._vector_field,
                    index_params=self.index_params,
                    using=self.alias,
                )

            # If default did not work, most likely on Zilliz Cloud
            except MilvusException:
                # Use AUTOINDEX based index
                self.index_params = {
                    "metric_type": "L2",
                    "index_type": "AUTOINDEX",
                    "params": {},
                }
                self.col.create_index(
                    self._vector_field,
                    index_params=self.index_params,
                    using=self.alias,
                )
            logger.debug(
                "Successfully created an index on collection: %s",
                self.collection_name,
            )

        except MilvusException as e:
            logger.error(
                "Failed to create an index on collection: %s", self.collection_name
            )
            raise e

Error Message and Stack Trace (if applicable)

No response

Description

We are trying to use Langchain_milvus library to create milvus collection using metadata. Now latest version of milvus support Scalar Index for other column also. we have requirement to add Scalar Index for batter performance in filtering data.

Currently langchain milvus support to add index only for VECTOR field only.

We can use metadata_schema logic to support indexing on Scalar fields.

#23219

System Info

langchain-core==0.2.20
langchain-community==0.2.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions