ReMe/reme/schema/file_chunk.py
Sen Huang e31db5fe19
docs: rename vault_dir to workspace_dir in documentation and examples (#286)
* docs: rename vault_dir to workspace_dir in documentation and examples

* refactor(extract): format long method call across multiple lines

* refactor(extract): format system prompt parameters for better readability
2026-06-22 16:58:57 +08:00

26 lines
1,015 B
Python

"""File chunk — an embedding node tied to a line range in a file."""
from pydantic import Field
from .emb_node import EmbNode
class FileChunk(EmbNode):
"""A chunk of a file with positional info and per-stage retrieval scores."""
path: str = Field(default="", description="Path relative to the workspace")
start_line: int = Field(default=0, description="Inclusive start line (1-based)")
end_line: int = Field(default=0, description="Inclusive end line (1-based)")
scores: dict[str, float] = Field(default_factory=dict, description="Retrieval scores keyed by stage")
@property
def score(self) -> float:
"""Final aggregated score; 0.0 if not yet computed."""
return self.scores.get("score", 0.0)
def set_hash_id(self):
"""Replace ``id`` with a deterministic hash of (path, range, text)."""
from ..utils import hash_text
self.id = hash_text(" ".join([self.path, str(self.start_line), str(self.end_line), self.text]))
return self