Spaces:
Sleeping
Sleeping
File size: 1,134 Bytes
68a4a6e | 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 | """
models.py
Pydantic models for the RAG query pipeline.
"""
from typing import List
from pydantic import BaseModel
class SearchResult(BaseModel):
"""A single chunk retrieved from Qdrant."""
chunk_id: str
text: str
source: str
file_path: str
score: float
class RankedResult(BaseModel):
"""A chunk after Cohere reranking."""
chunk_id: str
text: str
source: str
file_path: str
rerank_score: float
class QueryResponse(BaseModel):
"""Full response returned to the Gradio UI."""
answer: str
sources: List[RankedResult]
def format_for_gradio(self) -> str:
"""
Format as a single markdown string for Gradio ChatInterface.
Answer followed by a deduplicated numbered source list.
"""
lines = [self.answer, "\n**Sources:**"]
seen = set()
for i, src in enumerate(self.sources, 1):
if src.file_path in seen:
continue
seen.add(src.file_path)
lines.append(f"{i}. `{src.source}` — {src.file_path}")
return "\n".join(lines)
|