Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor: replace bare dict with dict[str, Any] in VDB providers (#35110)

wdeveloper164ee1bd5f3269
diff --git a/api/providers/vdb/vdb-elasticsearch/src/dify_vdb_elasticsearch/elasticsearch_vector.py b/api/providers/vdb/vdb-elasticsearch/src/dify_vdb_elasticsearch/elasticsearch_vector.py
index 1470713b887..11463b6c58c 100644
--- a/api/providers/vdb/vdb-elasticsearch/src/dify_vdb_elasticsearch/elasticsearch_vector.py
+++ b/api/providers/vdb/vdb-elasticsearch/src/dify_vdb_elasticsearch/elasticsearch_vector.py
@@ -43,7 +43,7 @@ class ElasticSearchConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
use_cloud = values.get("use_cloud", False)
cloud_url = values.get("cloud_url")
@@ -258,7 +258,7 @@ class ElasticSearchVector(BaseVector):
self,
embeddings: list[list[float]],
metadatas: list[dict[Any, Any]] | None = None,
- index_params: dict | None = None,
+ index_params: dict[str, Any] | None = None,
):
lock_name = f"vector_indexing_lock_{self._collection_name}"
with redis_client.lock(lock_name, timeout=20):
diff --git a/api/providers/vdb/vdb-huawei-cloud/src/dify_vdb_huawei_cloud/huawei_cloud_vector.py b/api/providers/vdb/vdb-huawei-cloud/src/dify_vdb_huawei_cloud/huawei_cloud_vector.py
index 90d6d98c63c..d51075d2e8f 100644
--- a/api/providers/vdb/vdb-huawei-cloud/src/dify_vdb_huawei_cloud/huawei_cloud_vector.py
+++ b/api/providers/vdb/vdb-huawei-cloud/src/dify_vdb_huawei_cloud/huawei_cloud_vector.py
@@ -44,7 +44,7 @@ class HuaweiCloudVectorConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values["hosts"]:
raise ValueError("config HOSTS is required")
return values
@@ -169,7 +169,7 @@ class HuaweiCloudVector(BaseVector):
self,
embeddings: list[list[float]],
metadatas: list[dict[Any, Any]] | None = None,
- index_params: dict | None = None,
+ index_params: dict[str, Any] | None = None,
):
lock_name = f"vector_indexing_lock_{self._collection_name}"
with redis_client.lock(lock_name, timeout=20):
diff --git a/api/providers/vdb/vdb-lindorm/src/dify_vdb_lindorm/lindorm_vector.py b/api/providers/vdb/vdb-lindorm/src/dify_vdb_lindorm/lindorm_vector.py
index fbe0bcad020..9187ca943dc 100644
--- a/api/providers/vdb/vdb-lindorm/src/dify_vdb_lindorm/lindorm_vector.py
+++ b/api/providers/vdb/vdb-lindorm/src/dify_vdb_lindorm/lindorm_vector.py
@@ -44,7 +44,7 @@ class LindormVectorStoreConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values["hosts"]:
raise ValueError("config URL is required")
if not values["username"]:
@@ -336,7 +336,10 @@ class LindormVectorStore(BaseVector):
return docs
def create_collection(
- self, embeddings: list, metadatas: list[dict] | None = None, index_params: dict | None = None
+ self,
+ embeddings: list[list[float]],
+ metadatas: list[dict[str, Any]] | None = None,
+ index_params: dict[str, Any] | None = None,
):
if not embeddings:
raise ValueError(f"Embeddings list cannot be empty for collection create '{self._collection_name}'")
diff --git a/api/providers/vdb/vdb-milvus/src/dify_vdb_milvus/milvus_vector.py b/api/providers/vdb/vdb-milvus/src/dify_vdb_milvus/milvus_vector.py
index 7cdb2d3a998..46f3224a952 100644
--- a/api/providers/vdb/vdb-milvus/src/dify_vdb_milvus/milvus_vector.py
+++ b/api/providers/vdb/vdb-milvus/src/dify_vdb_milvus/milvus_vector.py
@@ -45,7 +45,7 @@ class MilvusConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
"""
Validate the configuration values.
Raises ValueError if required fields are missing.
@@ -302,7 +302,10 @@ class MilvusVector(BaseVector):
)
def create_collection(
- self, embeddings: list, metadatas: list[dict] | None = None, index_params: dict | None = None
+ self,
+ embeddings: list[list[float]],
+ metadatas: list[dict[str, Any]] | None = None,
+ index_params: dict[str, Any] | None = None,
):
"""
Create a new collection in Milvus with the specified schema and index parameters.
diff --git a/api/providers/vdb/vdb-opensearch/src/dify_vdb_opensearch/opensearch_vector.py b/api/providers/vdb/vdb-opensearch/src/dify_vdb_opensearch/opensearch_vector.py
index 50d18cdc4c1..843c495d823 100644
--- a/api/providers/vdb/vdb-opensearch/src/dify_vdb_opensearch/opensearch_vector.py
+++ b/api/providers/vdb/vdb-opensearch/src/dify_vdb_opensearch/opensearch_vector.py
@@ -49,7 +49,7 @@ class OpenSearchConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values.get("host"):
raise ValueError("config OPENSEARCH_HOST is required")
if not values.get("port"):
@@ -252,7 +252,10 @@ class OpenSearchVector(BaseVector):
return docs
def create_collection(
- self, embeddings: list, metadatas: list[dict] | None = None, index_params: dict | None = None
+ self,
+ embeddings: list[list[float]],
+ metadatas: list[dict[str, Any]] | None = None,
+ index_params: dict[str, Any] | None = None,
):
lock_name = f"vector_indexing_lock_{self._collection_name.lower()}"
with redis_client.lock(lock_name, timeout=20):
diff --git a/api/providers/vdb/vdb-pgvector/src/dify_vdb_pgvector/pgvector.py b/api/providers/vdb/vdb-pgvector/src/dify_vdb_pgvector/pgvector.py
index 0615b8312cb..b1bdce0ad44 100644
--- a/api/providers/vdb/vdb-pgvector/src/dify_vdb_pgvector/pgvector.py
+++ b/api/providers/vdb/vdb-pgvector/src/dify_vdb_pgvector/pgvector.py
@@ -34,7 +34,7 @@ class PGVectorConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values["host"]:
raise ValueError("config PGVECTOR_HOST is required")
if not values["port"]:
diff --git a/api/providers/vdb/vdb-relyt/src/dify_vdb_relyt/relyt_vector.py b/api/providers/vdb/vdb-relyt/src/dify_vdb_relyt/relyt_vector.py
index 64b45bf28be..336c2d3c8af 100644
--- a/api/providers/vdb/vdb-relyt/src/dify_vdb_relyt/relyt_vector.py
+++ b/api/providers/vdb/vdb-relyt/src/dify_vdb_relyt/relyt_vector.py
@@ -38,7 +38,7 @@ class RelytConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values["host"]:
raise ValueError("config RELYT_HOST is required")
if not values["port"]:
@@ -239,7 +239,7 @@ class RelytVector(BaseVector):
self,
embedding: list[float],
k: int = 4,
- filter: dict | None = None,
+ filter: dict[str, Any] | None = None,
) -> list[tuple[Document, float]]:
# Add the filter if provided
diff --git a/api/providers/vdb/vdb-tablestore/src/dify_vdb_tablestore/tablestore_vector.py b/api/providers/vdb/vdb-tablestore/src/dify_vdb_tablestore/tablestore_vector.py
index 4a734232ec1..f9deac11e5e 100644
--- a/api/providers/vdb/vdb-tablestore/src/dify_vdb_tablestore/tablestore_vector.py
+++ b/api/providers/vdb/vdb-tablestore/src/dify_vdb_tablestore/tablestore_vector.py
@@ -30,7 +30,7 @@ class TableStoreConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values["access_key_id"]:
raise ValueError("config ACCESS_KEY_ID is required")
if not values["access_key_secret"]:
diff --git a/api/providers/vdb/vdb-tidb-vector/src/dify_vdb_tidb_vector/tidb_vector.py b/api/providers/vdb/vdb-tidb-vector/src/dify_vdb_tidb_vector/tidb_vector.py
index e3216810932..c696a685ddd 100644
--- a/api/providers/vdb/vdb-tidb-vector/src/dify_vdb_tidb_vector/tidb_vector.py
+++ b/api/providers/vdb/vdb-tidb-vector/src/dify_vdb_tidb_vector/tidb_vector.py
@@ -31,7 +31,7 @@ class TiDBVectorConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values["host"]:
raise ValueError("config TIDB_VECTOR_HOST is required")
if not values["port"]:
diff --git a/api/providers/vdb/vdb-upstash/src/dify_vdb_upstash/upstash_vector.py b/api/providers/vdb/vdb-upstash/src/dify_vdb_upstash/upstash_vector.py
index 289d9718533..75d70a19647 100644
--- a/api/providers/vdb/vdb-upstash/src/dify_vdb_upstash/upstash_vector.py
+++ b/api/providers/vdb/vdb-upstash/src/dify_vdb_upstash/upstash_vector.py
@@ -20,7 +20,7 @@ class UpstashVectorConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values["url"]:
raise ValueError("Upstash URL is required")
if not values["token"]:
diff --git a/api/providers/vdb/vdb-vastbase/src/dify_vdb_vastbase/vastbase_vector.py b/api/providers/vdb/vdb-vastbase/src/dify_vdb_vastbase/vastbase_vector.py
index d080e8da580..ab00f9db28e 100644
--- a/api/providers/vdb/vdb-vastbase/src/dify_vdb_vastbase/vastbase_vector.py
+++ b/api/providers/vdb/vdb-vastbase/src/dify_vdb_vastbase/vastbase_vector.py
@@ -28,7 +28,7 @@ class VastbaseVectorConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict):
+ def validate_config(cls, values: dict[str, Any]):
if not values["host"]:
raise ValueError("config VASTBASE_HOST is required")
if not values["port"]:
diff --git a/api/providers/vdb/vdb-weaviate/src/dify_vdb_weaviate/weaviate_vector.py b/api/providers/vdb/vdb-weaviate/src/dify_vdb_weaviate/weaviate_vector.py
index 25b65b82a93..81eb3d84ae1 100644
--- a/api/providers/vdb/vdb-weaviate/src/dify_vdb_weaviate/weaviate_vector.py
+++ b/api/providers/vdb/vdb-weaviate/src/dify_vdb_weaviate/weaviate_vector.py
@@ -82,7 +82,7 @@ class WeaviateConfig(BaseModel):
@model_validator(mode="before")
@classmethod
- def validate_config(cls, values: dict) -> dict:
+ def validate_config(cls, values: dict[str, Any]) -> dict[str, Any]:
"""Validates that required configuration values are present."""
if not values["endpoint"]:
raise ValueError("config WEAVIATE_ENDPOINT is required")