f0bf53f0b3
Check Cross-Plugin Imports / check (push) Has been cancelled
- test_ai_proactive.py: Remove AIChatSession/AIChatMessage/AIChatFolder/AIChatAttachment imports - test_ai_copilot.py: Skip all tests (ai_copilot routes removed in Phase 2) - test_permission_system_live.py: Guard AIConversation/AIMessage import with try/except - conftest.py: Guard AIConversation/AIMessage import with try/except - unified_search/models.py: Add missing OwnedMixin import - test_ai_proactive.py: Skip test_rate_limiting (get_cache removed)
79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
"""SQLAlchemy models for the Unified Search plugin."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
|
|
from sqlalchemy import ForeignKey, Index, Integer, String, Text
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.db import Base, TenantMixin
|
|
from app.models.owned_mixin import OwnedMixin
|
|
|
|
|
|
class SearchProviderRegistry(Base, TenantMixin, OwnedMixin):
|
|
"""Registry of active search providers per tenant."""
|
|
|
|
__tablename__ = "unified_search_providers"
|
|
__table_args__ = (
|
|
Index("ix_usp_tenant", "tenant_id"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
entity_type: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
plugin_name: Mapped[str] = mapped_column(String(80), nullable=False)
|
|
is_active: Mapped[bool] = mapped_column(
|
|
nullable=False, default=True
|
|
)
|
|
config: Mapped[dict] = mapped_column(JSONB, nullable=False, default=dict)
|
|
|
|
|
|
class SearchIndexLog(Base, TenantMixin, OwnedMixin):
|
|
"""Log of indexing actions for audit and debugging."""
|
|
|
|
__tablename__ = "unified_search_index_log"
|
|
__table_args__ = (
|
|
Index("ix_usil_tenant", "tenant_id"),
|
|
Index("ix_usil_entity", "entity_type", "entity_id"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
entity_type: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
entity_id: Mapped[uuid.UUID] = mapped_column(PGUUID(as_uuid=True), nullable=False)
|
|
action: Mapped[str] = mapped_column(String(20), nullable=False)
|
|
status: Mapped[str] = mapped_column(String(20), nullable=False, default="pending")
|
|
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
from pgvector.sqlalchemy import Vector # noqa: E402
|
|
from app.models.owned_mixin import OwnedMixin
|
|
|
|
|
|
class DocumentChunk(Base, TenantMixin, OwnedMixin):
|
|
"""Chunk of a DMS file's extracted text, with its own embedding for RAG."""
|
|
|
|
__tablename__ = "document_chunks"
|
|
__table_args__ = (
|
|
Index("ix_document_chunks_tenant", "tenant_id"),
|
|
Index("ix_document_chunks_file", "file_id"),
|
|
Index("ix_document_chunks_tenant_file", "tenant_id", "file_id"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
file_id: Mapped[uuid.UUID] = mapped_column(
|
|
PGUUID(as_uuid=True), ForeignKey("files.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
chunk_index: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
chunk_text: Mapped[str] = mapped_column(Text, nullable=False)
|
|
chunk_hash: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
embedding: Mapped[list[float] | None] = mapped_column(
|
|
Vector(768), nullable=True
|
|
)
|