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

feat: Set parameters for Milvus using the configuration file #998 #1001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions autorag/vectordb/milvus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import List, Tuple, Optional
from typing import Any, Dict, List, Tuple, Optional

from pymilvus import (
DataType,
Expand All @@ -24,13 +24,15 @@ def __init__(
embedding_model: str,
collection_name: str,
embedding_batch: int = 100,
similarity_metric: str = "cosine",
similarity_metric: str = "l2",
index_type: str = "IVF_FLAT",
uri: str = "http://localhost:19530",
db_name: str = "",
token: str = "",
user: str = "",
password: str = "",
timeout: Optional[float] = None,
params: Dict[str, Any] = {},
):
super().__init__(embedding_model, similarity_metric, embedding_batch)

Expand All @@ -45,6 +47,9 @@ def __init__(
)
self.collection_name = collection_name
self.timeout = timeout
self.params = params
self.index_type = index_type

# Set Collection
if not utility.has_collection(collection_name, timeout=timeout):
# Get the dimension of the embeddings
Expand All @@ -66,6 +71,14 @@ def __init__(
schema = CollectionSchema(fields=[pk, field])

self.collection = Collection(name=self.collection_name, schema=schema)
index_params = {
"metric_type": self.similarity_metric.upper(),
"index_type": self.index_type.upper(),
"params": self.params,
}
self.collection.create_index(
field_name="vector", index_params=index_params, timeout=self.timeout
)
else:
self.collection = Collection(name=self.collection_name)

Expand All @@ -88,15 +101,6 @@ async def add(self, ids: List[str], texts: List[str]):

self.collection.flush(timeout=self.timeout)

index_params = {
"index_type": "IVF_FLAT",
"metric_type": self.similarity_metric.upper(),
"params": {},
} # TODO : add params
self.collection.create_index(
field_name="vector", index_params=index_params, timeout=self.timeout
)

async def query(
self, queries: List[str], top_k: int, **kwargs
) -> Tuple[List[List[str]], List[List[float]]]:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ scikit-learn
emoji

### Vector DB ###
pymilvus # for using milvus vectordb
pymilvus>=2.3.0 # for using milvus vectordb
chromadb>=0.5.0 # for chroma vectordb
weaviate-client # for weaviate vectordb
pinecone[grpc] # for pinecone vectordb
Expand Down