Skip to content

Commit 936bece

Browse files
authored
Merge pull request #1150 from tisnik/lcore-1241-better-ragchunkmodel
LCORE-1241: better RAGChunk model
2 parents 310a8f2 + f9e5fd8 commit 936bece

2 files changed

Lines changed: 9 additions & 17 deletions

File tree

src/utils/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ class RAGChunk(BaseModel):
154154
"""Model representing a RAG chunk used in the response."""
155155

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

160160

161161
class ReferencedDocument(BaseModel):

tests/unit/models/responses/test_rag_chunk.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,35 @@ def test_constructor_with_content_and_source(self) -> None:
3939
chunk = RAGChunk(
4040
content="Container orchestration automates deployment",
4141
source="docs/concepts.md",
42-
) # pyright: ignore[reportCallIssue]
42+
)
4343
assert chunk.content == "Container orchestration automates deployment"
4444
assert chunk.source == "docs/concepts.md"
4545
assert chunk.score is None
4646

4747
def test_constructor_with_content_and_score(self) -> None:
4848
"""Test RAGChunk constructor with content and score."""
49-
chunk = RAGChunk(
50-
content="Pod is the smallest deployable unit", score=0.82
51-
) # pyright: ignore[reportCallIssue]
49+
chunk = RAGChunk(content="Pod is the smallest deployable unit", score=0.82)
5250
assert chunk.content == "Pod is the smallest deployable unit"
5351
assert chunk.source is None
5452
assert chunk.score == 0.82
5553

5654
def test_score_range_validation(self) -> None:
5755
"""Test that RAGChunk accepts valid score ranges."""
5856
# Test minimum score
59-
chunk_min = RAGChunk(
60-
content="Test content", score=0.0
61-
) # pyright: ignore[reportCallIssue]
57+
chunk_min = RAGChunk(content="Test content", score=0.0)
6258
assert chunk_min.score == 0.0
6359

6460
# Test maximum score
65-
chunk_max = RAGChunk(
66-
content="Test content", score=1.0
67-
) # pyright: ignore[reportCallIssue]
61+
chunk_max = RAGChunk(content="Test content", score=1.0)
6862
assert chunk_max.score == 1.0
6963

7064
# Test decimal score
71-
chunk_decimal = RAGChunk(
72-
content="Test content", score=0.751
73-
) # pyright: ignore[reportCallIssue]
65+
chunk_decimal = RAGChunk(content="Test content", score=0.751)
7466
assert chunk_decimal.score == 0.751
7567

7668
def test_empty_content(self) -> None:
7769
"""Test RAGChunk with empty content."""
78-
chunk = RAGChunk(content="") # pyright: ignore[reportCallIssue]
70+
chunk = RAGChunk(content="")
7971
assert chunk.content == ""
8072
assert chunk.source is None
8173
assert chunk.score is None
@@ -107,7 +99,7 @@ def test_long_source_path(self) -> None:
10799
)
108100
chunk = RAGChunk(
109101
content="Content from deeply nested document", source=long_source
110-
) # pyright: ignore[reportCallIssue]
102+
)
111103
assert chunk.source == long_source
112104

113105
def test_url_as_source(self) -> None:

0 commit comments

Comments
 (0)