Document fast/deep search modes in README, enforce strict 30s/120s timeout behavior with 504 responses, and cap Jina search hits to 10 while exposing richer SSE process events for frontend interaction. Made-with: Cursor
74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class SearchRequest(BaseModel):
|
|
query: str = Field(min_length=1, description="User search query")
|
|
top_k_pages: int | None = Field(default=None, ge=1, le=10)
|
|
max_page_chars: int | None = Field(default=None, ge=500, le=20000)
|
|
search_mode: Literal["fast", "deep"] = "fast"
|
|
callback_url: str | None = None
|
|
|
|
|
|
class SearchResult(BaseModel):
|
|
url: str
|
|
title: str = ""
|
|
snippet: str = ""
|
|
rank: int = 0
|
|
|
|
|
|
class PageContent(BaseModel):
|
|
url: str
|
|
title: str = ""
|
|
content: str = ""
|
|
fetched: bool = True
|
|
usable: bool = True
|
|
error: str | None = None
|
|
|
|
|
|
class Citation(BaseModel):
|
|
title: str = ""
|
|
url: str
|
|
trust_score: float = Field(default=0.6, ge=0.0, le=1.0)
|
|
|
|
|
|
class KnowledgeTriple(BaseModel):
|
|
subject: str
|
|
predicate: str
|
|
object: str
|
|
|
|
|
|
class AnswerPayload(BaseModel):
|
|
summary: str
|
|
key_points: list[str] = Field(default_factory=list)
|
|
caveats: list[str] = Field(default_factory=list)
|
|
citations: list[Citation] = Field(default_factory=list)
|
|
follow_up_questions: list[str] = Field(default_factory=list)
|
|
confidence: float = Field(default=0.8, ge=0.0, le=1.0)
|
|
|
|
class SearchRoundTrace(BaseModel):
|
|
round_index: int
|
|
query: str
|
|
queries: list[str] = Field(default_factory=list)
|
|
result_count: int = 0
|
|
fetched_page_count: int = 0
|
|
usable_page_count: int = 0
|
|
reflection: str = ""
|
|
|
|
class SearchResponse(BaseModel):
|
|
query: str
|
|
search_mode: Literal["fast", "deep"] = "fast"
|
|
answer: AnswerPayload
|
|
search_results: list[SearchResult] = Field(default_factory=list)
|
|
pages: list[PageContent] = Field(default_factory=list)
|
|
search_rounds: list[SearchRoundTrace] = Field(default_factory=list)
|
|
knowledge_triples: list[KnowledgeTriple] = Field(default_factory=list)
|
|
content_ready: bool = True
|
|
llm_called: bool = False
|
|
cache_hit: bool = False
|
|
error: str | None = None
|
|
audit_id: str | None = None
|