Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class RAGChunk(BaseModel):
"""Model representing a RAG chunk used in the response."""

content: str = Field(description="The content of the chunk")
source: Optional[str] = Field(None, description="Source document or URL")
score: Optional[float] = Field(None, description="Relevance score")
source: Optional[str] = Field(default=None, description="Source document or URL")
score: Optional[float] = Field(default=None, description="Relevance score")


class ReferencedDocument(BaseModel):
Expand Down
22 changes: 7 additions & 15 deletions tests/unit/models/responses/test_rag_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,35 @@ def test_constructor_with_content_and_source(self) -> None:
chunk = RAGChunk(
content="Container orchestration automates deployment",
source="docs/concepts.md",
) # pyright: ignore[reportCallIssue]
)
assert chunk.content == "Container orchestration automates deployment"
assert chunk.source == "docs/concepts.md"
assert chunk.score is None

def test_constructor_with_content_and_score(self) -> None:
"""Test RAGChunk constructor with content and score."""
chunk = RAGChunk(
content="Pod is the smallest deployable unit", score=0.82
) # pyright: ignore[reportCallIssue]
chunk = RAGChunk(content="Pod is the smallest deployable unit", score=0.82)
assert chunk.content == "Pod is the smallest deployable unit"
assert chunk.source is None
assert chunk.score == 0.82

def test_score_range_validation(self) -> None:
"""Test that RAGChunk accepts valid score ranges."""
# Test minimum score
chunk_min = RAGChunk(
content="Test content", score=0.0
) # pyright: ignore[reportCallIssue]
chunk_min = RAGChunk(content="Test content", score=0.0)
assert chunk_min.score == 0.0

# Test maximum score
chunk_max = RAGChunk(
content="Test content", score=1.0
) # pyright: ignore[reportCallIssue]
chunk_max = RAGChunk(content="Test content", score=1.0)
assert chunk_max.score == 1.0

# Test decimal score
chunk_decimal = RAGChunk(
content="Test content", score=0.751
) # pyright: ignore[reportCallIssue]
chunk_decimal = RAGChunk(content="Test content", score=0.751)
assert chunk_decimal.score == 0.751

def test_empty_content(self) -> None:
"""Test RAGChunk with empty content."""
chunk = RAGChunk(content="") # pyright: ignore[reportCallIssue]
chunk = RAGChunk(content="")
assert chunk.content == ""
assert chunk.source is None
assert chunk.score is None
Expand Down Expand Up @@ -107,7 +99,7 @@ def test_long_source_path(self) -> None:
)
chunk = RAGChunk(
content="Content from deeply nested document", source=long_source
) # pyright: ignore[reportCallIssue]
)
assert chunk.source == long_source

def test_url_as_source(self) -> None:
Expand Down
Loading