A chunk returned from a retrieval operation with associated metrics.
chunk.RetrievedChunk(
text,
start_index,
end_index,
char_count,
context=None,
origin=None,
attributes=None,
metrics=list(),
chunk_ids=list()
)
store.retrieve() returns RetrievedChunk objects rather than plain Chunks. Each one is an ordinary Chunk (text, position, context, origin, attributes) extended with the scores that explain why it was returned, so you can rank, threshold, or display results and still trace each passage back to its source.
In addition to the inherited Chunk fields, RetrievedChunk adds:
Parameters
metrics: list[Metric] = list()
-
Retrieval scores for this chunk, as a list of Metric objects. With the default hybrid retrieval a chunk may carry several (for example a vector similarity score and a BM25 score); higher values indicate a better match.
chunk_ids: list[int] = list()
-
Backend chunk identifiers represented by this retrieved chunk. A normal result contains a single id; a deoverlapped result that merged several adjacent chunks lists all of their ids.
Examples
Construct one directly to see its shape (in practice store.retrieve() builds these for you). Here we attach two scores and then read them back:
from raghilda.chunk import RetrievedChunk, Metric
chunk = RetrievedChunk(
text="This is relevant content.",
start_index=0,
end_index=25,
char_count=25,
metrics=[
Metric(name="similarity", value=0.92),
Metric(name="bm25_score", value=15.3),
],
)
# Each Metric carries a name and a numeric score
for metric in chunk.metrics:
print(f"{metric.name}: {metric.value}")
similarity: 0.92
bm25_score: 15.3