Skip to content

Commit 73d3231

Browse files
authored
fix(api): accept verbatim extraction mode in bank manifests (#2576)
Co-authored-by: ishanmalik <16657815+ishanmalik@users.noreply.github.com>
1 parent 59d825d commit 73d3231

8 files changed

Lines changed: 29 additions & 15 deletions

File tree

hindsight-api-slim/hindsight_api/api/http.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def _parse_metadata(metadata: Any) -> dict[str, Any]:
5252
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
5353

5454
from hindsight_api import MemoryEngine
55+
from hindsight_api.config import RETAIN_EXTRACTION_MODES
5556

5657

5758
def _annotation_is_nullable(annotation: Any) -> bool:
@@ -1245,7 +1246,7 @@ class CreateBankRequest(BaseModel):
12451246
)
12461247
retain_extraction_mode: str | None = Field(
12471248
default=None,
1248-
description="Fact extraction mode: 'concise' (default), 'verbose', or 'custom'.",
1249+
description="Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'.",
12491250
)
12501251
retain_custom_instructions: str | None = Field(
12511252
default=None,
@@ -2206,7 +2207,8 @@ class BankTemplateConfig(BaseModel):
22062207
reflect_mission: str | None = Field(default=None, description="Mission/context for Reflect operations")
22072208
retain_mission: str | None = Field(default=None, description="Steers what gets extracted during retain")
22082209
retain_extraction_mode: str | None = Field(
2209-
default=None, description="Fact extraction mode: 'concise' (default), 'verbose', or 'custom'"
2210+
default=None,
2211+
description="Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'",
22102212
)
22112213
retain_custom_instructions: str | None = Field(
22122214
default=None, description="Custom extraction prompt (when mode='custom')"
@@ -2432,10 +2434,10 @@ def validate_bank_template(manifest: "BankTemplateManifest") -> list[str]:
24322434
if manifest.bank:
24332435
bank = manifest.bank
24342436
if bank.retain_extraction_mode is not None:
2435-
valid_modes = ("concise", "verbose", "custom", "chunks")
2436-
if bank.retain_extraction_mode not in valid_modes:
2437+
if bank.retain_extraction_mode not in RETAIN_EXTRACTION_MODES:
24372438
errors.append(
2438-
f"bank.retain_extraction_mode: must be one of {valid_modes}, got '{bank.retain_extraction_mode}'"
2439+
"bank.retain_extraction_mode: "
2440+
f"must be one of {RETAIN_EXTRACTION_MODES}, got '{bank.retain_extraction_mode}'"
24392441
)
24402442
if bank.retain_custom_instructions and bank.retain_extraction_mode != "custom":
24412443
errors.append("bank.retain_custom_instructions: requires retain_extraction_mode='custom'")

hindsight-api-slim/tests/test_bank_templates.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import httpx
66
from datetime import datetime
77
from hindsight_api.api import create_app
8+
from hindsight_api.api.http import BankTemplateManifest, validate_bank_template
89

910

1011
@pytest_asyncio.fixture
@@ -81,6 +82,17 @@ async def test_import_dry_run_valid(self, api_client, bank_id, sample_template):
8182
assert set(data["mental_models_created"]) == {"test-model-one", "test-model-two"}
8283
assert set(data["directives_created"]) == {"Be concise", "Use examples"}
8384

85+
def test_verbatim_extraction_mode_is_valid(self):
86+
"""verbatim is a valid retain extraction mode in bank manifests."""
87+
manifest = BankTemplateManifest.model_validate(
88+
{
89+
"version": "1",
90+
"bank": {"retain_extraction_mode": "verbatim"},
91+
}
92+
)
93+
94+
assert validate_bank_template(manifest) == []
95+
8496
@pytest.mark.asyncio
8597
async def test_import_invalid_version(self, api_client, bank_id):
8698
"""Reject manifest with unsupported version."""

hindsight-clients/python/hindsight_client/hindsight_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def create_bank(
592592
disposition_empathy: Deprecated. Use update_bank_config(disposition_empathy=...) instead.
593593
disposition: Deprecated. Use update_bank_config(disposition_skepticism=...) instead.
594594
retain_mission: Steers what gets extracted during retain(). Injected alongside built-in rules.
595-
retain_extraction_mode: Fact extraction mode: 'concise' (default), 'verbose', or 'custom'.
595+
retain_extraction_mode: Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'.
596596
retain_custom_instructions: Custom extraction prompt (only active when mode is 'custom').
597597
retain_chunk_size: Target maximum characters for each content chunk during retain.
598598
retain_structured_chunk_size: Maximum characters for a single JSONL line or conversation
@@ -731,7 +731,7 @@ async def acreate_bank(
731731
disposition_empathy: Deprecated. Use update_bank_config(disposition_empathy=...) instead.
732732
disposition: Deprecated. Use update_bank_config(disposition_skepticism=...) instead.
733733
retain_mission: Steers what gets extracted during retain(). Injected alongside built-in rules.
734-
retain_extraction_mode: Fact extraction mode: 'concise' (default), 'verbose', or 'custom'.
734+
retain_extraction_mode: Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'.
735735
retain_custom_instructions: Custom extraction prompt (only active when mode is 'custom').
736736
retain_chunk_size: Target maximum characters for each content chunk during retain.
737737
retain_structured_chunk_size: Maximum characters for a single JSONL line or conversation

hindsight-clients/typescript/generated/types.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ export type BankTemplateConfig = {
453453
/**
454454
* Retain Extraction Mode
455455
*
456-
* Fact extraction mode: 'concise' (default), 'verbose', or 'custom'
456+
* Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'
457457
*/
458458
retain_extraction_mode?: string | null;
459459
/**
@@ -1080,7 +1080,7 @@ export type CreateBankRequest = {
10801080
/**
10811081
* Retain Extraction Mode
10821082
*
1083-
* Fact extraction mode: 'concise' (default), 'verbose', or 'custom'.
1083+
* Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'.
10841084
*/
10851085
retain_extraction_mode?: string | null;
10861086
/**

hindsight-clients/typescript/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ export class HindsightClient {
500500
dispositionEmpathy?: number;
501501
/** Steers what gets extracted during retain(). Injected alongside built-in rules. */
502502
retainMission?: string;
503-
/** Fact extraction mode: 'concise' (default), 'verbose', or 'custom'. */
503+
/** Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'. */
504504
retainExtractionMode?: string;
505505
/** Custom extraction prompt (only active when retainExtractionMode is 'custom'). */
506506
retainCustomInstructions?: string;

hindsight-docs/static/bank-template-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040
],
4141
"default": null,
42-
"description": "Fact extraction mode: 'concise' (default), 'verbose', or 'custom'",
42+
"description": "Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'",
4343
"title": "Retain Extraction Mode"
4444
},
4545
"retain_custom_instructions": {

hindsight-docs/static/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6592,7 +6592,7 @@
65926592
}
65936593
],
65946594
"title": "Retain Extraction Mode",
6595-
"description": "Fact extraction mode: 'concise' (default), 'verbose', or 'custom'"
6595+
"description": "Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'"
65966596
},
65976597
"retain_custom_instructions": {
65986598
"anyOf": [
@@ -7631,7 +7631,7 @@
76317631
}
76327632
],
76337633
"title": "Retain Extraction Mode",
7634-
"description": "Fact extraction mode: 'concise' (default), 'verbose', or 'custom'."
7634+
"description": "Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'."
76357635
},
76367636
"retain_custom_instructions": {
76377637
"anyOf": [

skills/hindsight-docs/references/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6592,7 +6592,7 @@
65926592
}
65936593
],
65946594
"title": "Retain Extraction Mode",
6595-
"description": "Fact extraction mode: 'concise' (default), 'verbose', or 'custom'"
6595+
"description": "Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'"
65966596
},
65976597
"retain_custom_instructions": {
65986598
"anyOf": [
@@ -7631,7 +7631,7 @@
76317631
}
76327632
],
76337633
"title": "Retain Extraction Mode",
7634-
"description": "Fact extraction mode: 'concise' (default), 'verbose', or 'custom'."
7634+
"description": "Fact extraction mode: 'concise' (default), 'verbose', 'custom', 'verbatim', or 'chunks'."
76357635
},
76367636
"retain_custom_instructions": {
76377637
"anyOf": [

0 commit comments

Comments
 (0)