From 79741fa8a4b7310ecd281a7ff51086a37ce1cc25 Mon Sep 17 00:00:00 2001 From: Asuka Minato Date: Fri, 18 Jul 2025 21:06:04 +0900 Subject: [PATCH] apply exact Python types as needed using Mapped --- .../datasource/vdb/pgvecto_rs/pgvecto_rs.py | 2 +- api/models/account.py | 32 ++++++++++--------- api/models/dataset.py | 15 +++++---- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/api/core/rag/datasource/vdb/pgvecto_rs/pgvecto_rs.py b/api/core/rag/datasource/vdb/pgvecto_rs/pgvecto_rs.py index 46aefef11d..1b567415e6 100644 --- a/api/core/rag/datasource/vdb/pgvecto_rs/pgvecto_rs.py +++ b/api/core/rag/datasource/vdb/pgvecto_rs/pgvecto_rs.py @@ -67,7 +67,7 @@ class PGVectoRS(BaseVector): postgresql.UUID(as_uuid=True), primary_key=True, ) - text: Mapped[str] = mapped_column(String) + text: Mapped[str] meta: Mapped[dict] = mapped_column(postgresql.JSONB) vector: Mapped[ndarray] = mapped_column(VECTOR(dim)) diff --git a/api/models/account.py b/api/models/account.py index b287f707e5..c7b5b32de3 100644 --- a/api/models/account.py +++ b/api/models/account.py @@ -85,18 +85,20 @@ class Account(UserMixin, Base): __table_args__ = (db.PrimaryKeyConstraint("id", name="account_pkey"), db.Index("account_email_idx", "email")) id: Mapped[str] = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()")) - name = mapped_column(db.String(255), nullable=False) - email = mapped_column(db.String(255), nullable=False) - password = mapped_column(db.String(255), nullable=True) - password_salt = mapped_column(db.String(255), nullable=True) - avatar = mapped_column(db.String(255)) - interface_language = mapped_column(db.String(255)) - interface_theme = mapped_column(db.String(255)) - timezone = mapped_column(db.String(255)) + name: Mapped[str] = mapped_column(db.String(255)) + email: Mapped[str] = mapped_column(db.String(255)) + password: Mapped[Optional[str]] = mapped_column(db.String(255)) + password_salt: Mapped[Optional[str]] = mapped_column(db.String(255)) + avatar: Mapped[str] = mapped_column(db.String(255)) + interface_language: Mapped[str] = mapped_column(db.String(255)) + interface_theme: Mapped[str] = mapped_column(db.String(255)) + timezone: Mapped[str] = mapped_column(db.String(255)) last_login_at = mapped_column(db.DateTime) - last_login_ip = mapped_column(db.String(255)) + last_login_ip: Mapped[str] = mapped_column(db.String(255)) last_active_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) - status = mapped_column(db.String(16), nullable=False, server_default=db.text("'active'::character varying")) + status: Mapped[str] = mapped_column( + db.String(16), nullable=False, server_default=db.text("'active'::character varying") + ) initialized_at = mapped_column(db.DateTime) created_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) updated_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) @@ -197,10 +199,10 @@ class Tenant(Base): __table_args__ = (db.PrimaryKeyConstraint("id", name="tenant_pkey"),) id: Mapped[str] = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()")) - name = mapped_column(db.String(255), nullable=False) + name: Mapped[str] = mapped_column(db.String(255)) encrypt_public_key = mapped_column(db.Text) - plan = mapped_column(db.String(255), nullable=False, server_default=db.text("'basic'::character varying")) - status = mapped_column(db.String(255), nullable=False, server_default=db.text("'normal'::character varying")) + plan: Mapped[str] = mapped_column(db.String(255), server_default=db.text("'basic'::character varying")) + status: Mapped[str] = mapped_column(db.String(255), server_default=db.text("'normal'::character varying")) custom_config = mapped_column(db.Text) created_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) updated_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) @@ -251,8 +253,8 @@ class AccountIntegrate(Base): id = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()")) account_id = mapped_column(StringUUID, nullable=False) provider = mapped_column(db.String(16), nullable=False) - open_id = mapped_column(db.String(255), nullable=False) - encrypted_token = mapped_column(db.String(255), nullable=False) + open_id: Mapped[str] = mapped_column(db.String(255)) + encrypted_token: Mapped[str] = mapped_column(db.String(255)) created_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) updated_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) diff --git a/api/models/dataset.py b/api/models/dataset.py index 0644a9de7f..53cc85016e 100644 --- a/api/models/dataset.py +++ b/api/models/dataset.py @@ -1,3 +1,4 @@ +from typing import Optional import base64 import enum import hashlib @@ -47,19 +48,19 @@ class Dataset(Base): id = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()")) tenant_id = mapped_column(StringUUID, nullable=False) - name = mapped_column(db.String(255), nullable=False) + name: Mapped[str] = mapped_column(db.String(255)) description = mapped_column(db.Text, nullable=True) - provider = mapped_column(db.String(255), nullable=False, server_default=db.text("'vendor'::character varying")) - permission = mapped_column(db.String(255), nullable=False, server_default=db.text("'only_me'::character varying")) - data_source_type = mapped_column(db.String(255)) - indexing_technique = mapped_column(db.String(255), nullable=True) + provider: Mapped[str] = mapped_column(db.String(255), server_default=db.text("'vendor'::character varying")) + permission: Mapped[str] = mapped_column(db.String(255), server_default=db.text("'only_me'::character varying")) + data_source_type: Mapped[str] = mapped_column(db.String(255)) + indexing_technique: Mapped[Optional[str]] = mapped_column(db.String(255)) index_struct = mapped_column(db.Text, nullable=True) created_by = mapped_column(StringUUID, nullable=False) created_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) updated_by = mapped_column(StringUUID, nullable=True) updated_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp()) - embedding_model = mapped_column(db.String(255), nullable=True) - embedding_model_provider = mapped_column(db.String(255), nullable=True) + embedding_model: Mapped[str] = mapped_column(db.String(255), nullable=True) + embedding_model_provider: Mapped[str] = mapped_column(db.String(255), nullable=True) collection_binding_id = mapped_column(StringUUID, nullable=True) retrieval_model = mapped_column(JSONB, nullable=True) built_in_field_enabled = mapped_column(db.Boolean, nullable=False, server_default=db.text("false"))