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

1"""Request and response models for API endpoints.""" 

2 

3 

4from pydantic import BaseModel, Field 

5 

6from .schemas import DataRecord, SearchResult, TableSchema 

7 

8 

9# Table Management Requests 

10class CreateTableRequest(BaseModel): 

11 """Request to create a new table.""" 

12 

13 table_schema: TableSchema = Field(..., alias="schema", description="Table schema definition") 

14 

15 model_config = {"populate_by_name": True} 

16 

17 

18class DeleteTableRequest(BaseModel): 

19 """Request to delete a table (path parameter only).""" 

20 

21 pass 

22 

23 

24# Data Management Requests 

25class UpsertDataRequest(BaseModel): 

26 """Request to insert or update data records.""" 

27 

28 records: list[DataRecord] = Field(..., description="List of data records to upsert") 

29 

30 

31class DeleteDataRequest(BaseModel): 

32 """Request to delete a data record (path parameter only).""" 

33 

34 pass 

35 

36 

37# Search Requests 

38class SimilaritySearchRequest(BaseModel): 

39 """Request for similarity-based search.""" 

40 

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 ) 

48 

49 

50class TopKSearchRequest(BaseModel): 

51 """Request for top-k search.""" 

52 

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") 

55 

56 

57# Response Models 

58class CreateTableResponse(BaseModel): 

59 """Response for table creation.""" 

60 

61 message: str = Field(..., description="Success message") 

62 table_name: str = Field(..., description="Name of the created table") 

63 

64 

65class ListTablesResponse(BaseModel): 

66 """Response for listing tables.""" 

67 

68 tables: list[str] = Field(..., description="List of table names") 

69 count: int = Field(..., description="Number of tables") 

70 

71 

72class GetTableResponse(BaseModel): 

73 """Response for getting table schema.""" 

74 

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") 

78 

79 model_config = {"populate_by_name": True} 

80 

81 

82class UpsertDataResponse(BaseModel): 

83 """Response for data upsert operation.""" 

84 

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") 

88 

89 

90class DeleteDataResponse(BaseModel): 

91 """Response for data deletion.""" 

92 

93 message: str = Field(..., description="Success message") 

94 deleted_id: str = Field(..., description="ID of the deleted record") 

95 

96 

97class SearchResponse(BaseModel): 

98 """Response for search operations.""" 

99 

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 ) 

106 

107 

108class HealthResponse(BaseModel): 

109 """Health check response.""" 

110 

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")