bibraeval.RecordCollection

class bibraeval.RecordCollection(*, records=<factory>)

Bases: BaseModel, Generic

A collection of records keyed by document identifier.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

records (dict[str, Record[TypeVar]])

records: dict[str, Record[MetadataT]]
classmethod create_from_dir(directory, schema)

Load *.json records from a directory, using each filename stem as its document ID.

Files must contain JSON objects. Other files and nested directories are ignored.

Parameters:
  • directory (str | Path)

  • schema (type[MetadataT])

Return type:

RecordCollection[TypeVar]

classmethod create_from_file(file_path, schema)

Load JSONL records whose objects each contain a non-empty doc_id.

Blank lines are ignored. Duplicate IDs replace the earlier record.

Parameters:
  • file_path (str | Path)

  • schema (type[MetadataT])

Return type:

RecordCollection[TypeVar]

add_record(record)

Store a record, replacing any existing record with the same ID.

Parameters:

record (Record[TypeVar])

Return type:

None

get_record(doc_id)

Return a record by ID, or None when the ID is absent.

Parameters:

doc_id (str)

Return type:

Record[TypeVar] | None

add_payload(doc_id, payload, schema)

Validate payload against metadata schema and store payload, replacing an existing matching ID.

Parameters:
  • doc_id (str)

  • payload (dict[str, Any])

  • schema (type[MetadataT])

Return type:

Record[TypeVar]

as_list()

Return the stored records as a list in insertion order.

Return type:

list[Record[TypeVar]]

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].