Coverage for src/semware/models/requests.py: 100%
46 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-09 02:15 -0700
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-09 02:15 -0700
1"""Request and response models for API endpoints."""
4from pydantic import BaseModel, Field
6from .schemas import DataRecord, SearchResult, TableSchema
9# Table Management Requests
10class CreateTableRequest(BaseModel):
11 """Request to create a new table."""
13 table_schema: TableSchema = Field(..., alias="schema", description="Table schema definition")
15 model_config = {"populate_by_name": True}
18class DeleteTableRequest(BaseModel):
19 """Request to delete a table (path parameter only)."""
21 pass
24# Data Management Requests
25class UpsertDataRequest(BaseModel):
26 """Request to insert or update data records."""
28 records: list[DataRecord] = Field(..., description="List of data records to upsert")
31class DeleteDataRequest(BaseModel):
32 """Request to delete a data record (path parameter only)."""
34 pass
37# Search Requests
38class SimilaritySearchRequest(BaseModel):
39 """Request for similarity-based search."""
41 query: str = Field(..., description="Query text for semantic search")
42 threshold: float = Field(
43 ..., ge=0.0, le=1.0, description="Minimum similarity threshold (0.0 to 1.0)"
44 )
45 limit: int | None = Field(
46 None, gt=0, le=1000, description="Maximum number of results to return"
47 )
50class TopKSearchRequest(BaseModel):
51 """Request for top-k search."""
53 query: str = Field(..., description="Query text for semantic search")
54 k: int = Field(..., gt=0, le=1000, description="Number of top results to return")
57# Response Models
58class CreateTableResponse(BaseModel):
59 """Response for table creation."""
61 message: str = Field(..., description="Success message")
62 table_name: str = Field(..., description="Name of the created table")
65class ListTablesResponse(BaseModel):
66 """Response for listing tables."""
68 tables: list[str] = Field(..., description="List of table names")
69 count: int = Field(..., description="Number of tables")
72class GetTableResponse(BaseModel):
73 """Response for getting table schema."""
75 table_name: str = Field(..., description="Name of the table")
76 table_schema: TableSchema = Field(..., alias="schema", description="Table schema")
77 record_count: int = Field(..., description="Number of records in the table")
79 model_config = {"populate_by_name": True}
82class UpsertDataResponse(BaseModel):
83 """Response for data upsert operation."""
85 message: str = Field(..., description="Success message")
86 inserted_count: int = Field(..., description="Number of new records inserted")
87 updated_count: int = Field(..., description="Number of existing records updated")
90class DeleteDataResponse(BaseModel):
91 """Response for data deletion."""
93 message: str = Field(..., description="Success message")
94 deleted_id: str = Field(..., description="ID of the deleted record")
97class SearchResponse(BaseModel):
98 """Response for search operations."""
100 query: str = Field(..., description="Original query text")
101 results: list[SearchResult] = Field(..., description="Search results")
102 total_results: int = Field(..., description="Total number of results returned")
103 search_time_ms: float = Field(
104 ..., description="Search execution time in milliseconds"
105 )
108class HealthResponse(BaseModel):
109 """Health check response."""
111 status: str = Field(..., description="Service status")
112 app_name: str = Field(..., description="Application name")
113 version: str = Field(..., description="Application version")
114 timestamp: str = Field(..., description="Current timestamp")