File size: 1,377 Bytes
eec9162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Pydantic Models for FastAPI
===========================
Defines request and response schemas for all API endpoints.
Pydantic validates incoming JSON automatically — no manual checks needed.
"""

from pydantic import BaseModel
from typing import Optional


class QueryRequest(BaseModel):
    """
    Request body for POST /query
    Example: {"query": "What are NASA's latest space missions?"}
    """
    query: str


class QueryResponse(BaseModel):
    """
    Response body for POST /query

    Fields:
    - query:            the original query string sent by user
    - cache_hit:        True if a similar query was found in cache
    - matched_query:    the cached query that matched (None on miss)
    - similarity_score: cosine similarity between queries (0.0 on miss)
    - result:           the answer/document text
    - dominant_cluster: which GMM cluster this query belongs to
    """
    query:             str
    cache_hit:         bool
    matched_query:     Optional[str]
    similarity_score:  float
    result:            str
    dominant_cluster:  int


class CacheStats(BaseModel):
    """
    Response body for GET /cache/stats
    """
    total_entries: int
    hit_count:     int
    miss_count:    int
    hit_rate:      float


class FlushResponse(BaseModel):
    """
    Response body for DELETE /cache
    """
    status:  str
    message: str