Skip to content

Conversation

@maifeeulasad
Copy link

Description

closes #845

Tests and Documentation

Ran test with

python -m pytest tests/unit/memory/memory_interface/test_batching_scale.py -v

Then ran larger test suite with

python -m pytest tests/unit/**/**/*.py -v

Documented on code, where needed, as batching stays quite under the hood not sure if it requires changing any documentation or not. But willing to work on documentation part, if I missed something.

Open for upcoming reviews!

 - add `_SQLITE_MAX_BIND_VARS` constant to handle SQLite limits
 - implement batching in `get_scores()` for `score_ids` parameter
 - implement batching in `get_message_pieces()` for `prompt_ids`, `original_values`, `converted_values`, `converted_value_sha256`
 - implement batching in `get_attack_results()` for `attack_result_ids`, `objective_sha256 parameters`
 - implement batching in `get_scenario_results()` for `scenario_result_ids`
 - refactor necessary filter conditions across batched queries
 - handle empty list edge cases
)

```
python -m pytest tests/unit/memory/memory_interface/test_batching_scale.py -v
```
batch_param = "prompt_ids"
batch_values = [str(pi) for pi in prompt_ids]
batch_column = PromptMemoryEntry.id
elif original_values and len(original_values) > _SQLITE_MAX_BIND_VARS:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original code, it's possible to filter by all of these, not just one of them. Your changes assume it's at most one (see "elif").

)
if batch_values:
all_entries: MutableSequence[PromptMemoryEntry] = []
for i in range(0, len(batch_values), _SQLITE_MAX_BIND_VARS):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems to repeat several times. Is there a simple way to make this into a generic method that we can reuse?

@romanlutz romanlutz changed the title implement batching for memory interface FEAT implement batching for memory interface Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG get_scores_by_memory_labels and a few other memory methods do not scale

2 participants