Remove bounding boxes from citations, pass sources meta info from ResearchContext
This commit is contained in:
parent
75a086bae0
commit
6e31ea38a8
3 changed files with 11 additions and 42 deletions
|
|
@ -23,21 +23,14 @@ interface GapRecord {
|
||||||
resolved_by: string[];
|
resolved_by: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BoundingBox {
|
|
||||||
page_no: number;
|
|
||||||
left: number;
|
|
||||||
top: number;
|
|
||||||
right: number;
|
|
||||||
bottom: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Citation {
|
interface Citation {
|
||||||
|
document_id: string;
|
||||||
|
chunk_id: string;
|
||||||
document_uri: string;
|
document_uri: string;
|
||||||
document_title?: string;
|
document_title?: string;
|
||||||
page_numbers: number[];
|
page_numbers: number[];
|
||||||
headings?: string[];
|
headings?: string[];
|
||||||
content: string;
|
content: string;
|
||||||
bounding_boxes?: BoundingBox[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SearchAnswer {
|
interface SearchAnswer {
|
||||||
|
|
@ -612,35 +605,6 @@ export default function StateDisplay({ state }: StateDisplayProps) {
|
||||||
{citation.content.slice(0, 200)}
|
{citation.content.slice(0, 200)}
|
||||||
{citation.content.length > 200 && "…"}
|
{citation.content.length > 200 && "…"}
|
||||||
</div>
|
</div>
|
||||||
{citation.bounding_boxes &&
|
|
||||||
citation.bounding_boxes.length > 0 && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: "0.65rem",
|
|
||||||
color: "#a0aec0",
|
|
||||||
marginTop: "0.375rem",
|
|
||||||
display: "flex",
|
|
||||||
gap: "0.25rem",
|
|
||||||
flexWrap: "wrap",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{citation.bounding_boxes.map(
|
|
||||||
(bbox, bboxIdx) => (
|
|
||||||
<span
|
|
||||||
key={bboxIdx}
|
|
||||||
style={{
|
|
||||||
background: "#f7fafc",
|
|
||||||
padding: "0.125rem 0.25rem",
|
|
||||||
borderRadius: "2px",
|
|
||||||
border: "1px solid #e2e8f0",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
📍 p.{bbox.page_no} ({bbox.left.toFixed(0)},{bbox.top.toFixed(0)})
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, field_validator
|
from pydantic import BaseModel, Field, field_validator
|
||||||
|
|
||||||
from haiku.rag.store.models import BoundingBox
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from haiku.rag.store.models import SearchResult
|
from haiku.rag.store.models import SearchResult
|
||||||
|
|
||||||
|
|
@ -38,7 +36,6 @@ class Citation(BaseModel):
|
||||||
page_numbers: list[int] = Field(default_factory=list)
|
page_numbers: list[int] = Field(default_factory=list)
|
||||||
headings: list[str] | None = None
|
headings: list[str] | None = None
|
||||||
content: str
|
content: str
|
||||||
bounding_boxes: list[BoundingBox] | None = None
|
|
||||||
|
|
||||||
|
|
||||||
class SearchAnswer(BaseModel):
|
class SearchAnswer(BaseModel):
|
||||||
|
|
@ -84,7 +81,6 @@ def resolve_citations(
|
||||||
page_numbers=r.page_numbers,
|
page_numbers=r.page_numbers,
|
||||||
headings=r.headings,
|
headings=r.headings,
|
||||||
content=r.content,
|
content=r.content,
|
||||||
bounding_boxes=r.bounding_boxes,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return citations
|
return citations
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,15 @@ def format_context_for_prompt(context: ResearchContext) -> str:
|
||||||
"question": qa.query,
|
"question": qa.query,
|
||||||
"answer": qa.answer,
|
"answer": qa.answer,
|
||||||
"confidence": qa.confidence,
|
"confidence": qa.confidence,
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"document_uri": c.document_uri,
|
||||||
|
"document_title": c.document_title,
|
||||||
|
"page_numbers": c.page_numbers,
|
||||||
|
"headings": c.headings,
|
||||||
|
}
|
||||||
|
for c in qa.citations
|
||||||
|
],
|
||||||
}
|
}
|
||||||
for qa in context.qa_responses
|
for qa in context.qa_responses
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue