fleet-memory/hindsight-api/hindsight_api/alembic/versions
Nicolò Boschi 9b96becc5c
feat: entity labels — optional, free_values, multi_value, UI polish (#450)
* feat: entity labels

* feat: entity labels — optional, free_values, multi_value, UI polish

Completes the entity labels system:

**Schema & extraction**
- Dynamic Pydantic Labels model per fact: each group becomes a typed
  field (Literal | None, list[Literal], str | None, or list[str])
- `optional: bool` flag per group — non-optional enum fields appear in
  JSON schema required array so structured-output providers enforce them
- `free_values: bool` flag per group — accepts any LLM-generated string
  instead of a predefined enum; example values shown as hints in prompt
- New `is_label_entity()` helper for labels-only mode filtering that
  handles both enum lookup and free_values key-prefix matching
- Sentinel rejection: "None"/"null"/"n/a" strings dropped in post-processing

**BM25 / dense retrieval**
- `text_signals` column on memory_units: entity names + date tokens for
  enriched BM25 indexing without polluting stored fact text
- Dense embedding includes occurred_end when it differs from occurred_start
- Alembic migration z1u2v3w4x5y6 (merge revision fixing two heads)

**UI (bank-config-view)**
- Shadcn Switch replaces custom Toggle for both entity-labels and observations
- Shadcn Checkbox for multi/optional/free_values per group
- Input heights bumped to h-8 throughout the editor
- "Label Groups" → "Entity Labels", "Free-form entities" → "Entities"
- Free-text groups show "Example hints" banner in values section

**Tests (45 unit + 3 LLM integration)**
- build_labels_model: single, multi, mixed, free_values optional/required/multi
- is_label_entity: enum match, free_values prefix match, no false positives
- Post-processing: null/absent/string-None/free_values/sentinels/multi-value
- Schema: labels in required, structured object, no labels when unconfigured
- LLM integration: single-value enum, multi-value enum, free_values retain

**Docs**
- retain.md: new Entity Labels section covering groups, flags, examples
- configuration.md: retain_free_form_entities env var + entity_labels note

* fix(tests): update hierarchical fields count for entity_labels additions

entity_labels and retain_free_form_entities are hierarchical fields,
bumping the expected count from 11 to 13.

* fix(migration): rename text_signals revision to avoid collision with main

Main branch claimed z1u2v3w4x5y6 for observation_scopes. Rename our
text_signals migration to a2b3c4d5e6f7, chaining after z1u2v3w4x5y6.

* refactor(entity-labels): simplify free_values — always str|None, no multi

- free_values groups always produce str | None (multi_value and optional
  flags are ignored for free text groups — always optional, never multi)
- Prompt section for free_values groups shows only key + description,
  no values list (users put examples in the description instead)
- UI: section title "Entities", toggle "Free Form Entities", replace
  per-group checkboxes with a type dropdown (Enum / Free text); only
  show multi checkbox and values list when type is Enum
- Update tests to reflect new behaviour

* refactor(entity-labels): replace free_values/multi_value booleans with type field

- LabelGroup now uses type: "value" | "multi-values" | "text" instead of
  free_values/multi_value boolean pair
- Backward-compat migration converts legacy dicts automatically
- Rename retain_free_form_entities → entities_allow_free_form throughout
- Update UI dropdown to show Single value / Multi-values / Free text
- Remove separate multi checkbox (captured by type selection)
- Update docs examples and configuration.md
- Update all tests to use new field names

* fix(migration): backfill observation_scopes column for DBs with swapped z1u2v3w4x5y6

Local DBs that had z1u2v3w4x5y6 applied when it referred to the old
text_signals migration (before it was renamed to a2b3c4d5e6f7) won't have
observation_scopes in their memory_units table. This migration adds the
column with IF NOT EXISTS so it's a no-op on clean installs.

* feat(entity-labels): add tag field to auto-populate memory unit tags from labels

When a LabelGroup has tag=True, extracted key:value entities for that group
are automatically written to the memory unit's tags array. This lets entity
labels double as tags, enabling immediate filtering via the existing
tags/tags_match API params with no extra infrastructure.

- Add tag: bool = False to LabelGroup
- _inject_label_tags() helper called in both sync and batch extraction paths
- UI: add Tag checkbox per label group row
- Docs: document the new tag field
- Tests: 4 new unit tests covering all tag injection paths

* style: ruff format migration file

* fix(migration): fix multiple alembic heads after rebase — point text_signals after nullable_event_date

* fix(clients): update timestamp field to use Timestamp wrapper type after timestamp=unset feature

* style: ruff format agent.py

* fix(docs): update Go quickstart example to use NullableTimestamp for timestamp field
2026-03-02 13:05:25 +01:00
..
5a366d414dce_initial_schema.py feat: support azure pg_diskann (#381) 2026-02-16 16:08:54 +01:00
a1b2c3d4e5f6_add_file_storage_table.py feat: accept pdf, images and office files (#390) 2026-02-17 18:15:03 +01:00
a2b3c4d5e6f7_add_text_signals_column.py feat: entity labels — optional, free_values, multi_value, UI polish (#450) 2026-03-02 13:05:25 +01:00
aa2b3c4d5e6f_nullable_event_date.py feat: support timestamp="unset" to retain content without a date (#465) 2026-03-02 12:03:23 +01:00
b4c5d6e7f8a9_backfill_observation_scopes.py feat: entity labels — optional, free_values, multi_value, UI polish (#450) 2026-03-02 13:05:25 +01:00
b7c4d8e9f1a2_add_chunks_table.py misc: add mcp integration tests and increase test coverage (#98) 2026-01-05 11:16:55 +01:00
c8e5f2a3b4d1_add_retain_params_to_documents.py misc: add mcp integration tests and increase test coverage (#98) 2026-01-05 11:16:55 +01:00
d9f6a3b4c5e2_rename_bank_to_interactions.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
e0a1b2c3d4e5_disposition_to_3_traits.py misc: add mcp integration tests and increase test coverage (#98) 2026-01-05 11:16:55 +01:00
f1a2b3c4d5e6_add_memory_links_composite_index.py fix: improve mpfp retrieval (#146) 2026-01-12 18:58:05 +01:00
g2a3b4c5d6e7_add_tags_column.py feat: add memory tags (#152) 2026-01-13 18:28:40 +01:00
h3c4d5e6f7g8_mental_models_v4.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
i4d5e6f7g8h9_delete_opinions.py feat: introduce mental models (#132) 2026-01-16 11:16:41 +01:00
j5e6f7g8h9i0_mental_model_versions.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
k6f7g8h9i0j1_add_directive_subtype.py feat: improve mental model refresh and add directives (#166) 2026-01-19 11:38:35 +01:00
l7g8h9i0j1k2_add_worker_columns.py feat: new 'worker' service (#176) 2026-01-20 10:17:56 +01:00
m8h9i0j1k2l3_mental_model_id_to_text.py feat: revisit mental models, directives and reflections (#179) 2026-01-22 17:13:16 +01:00
n9i0j1k2l3m4_learnings_and_pinned_reflections.py feat: support azure pg_diskann (#381) 2026-02-16 16:08:54 +01:00
o0j1k2l3m4n5_migrate_mental_models_data.py feat: revisit mental models, directives and reflections (#179) 2026-01-22 17:13:16 +01:00
p1k2l3m4n5o6_new_knowledge_architecture.py feat: revisit mental models, directives and reflections (#179) 2026-01-22 17:13:16 +01:00
q2l3m4n5o6p7_fix_mental_model_fact_type.py feat: revisit mental models, directives and reflections (#179) 2026-01-22 17:13:16 +01:00
r3m4n5o6p7q8_add_reflect_response_to_reflections.py feat: revisit mental models, directives and reflections (#179) 2026-01-22 17:13:16 +01:00
rename_personality_to_disposition.py misc: add mcp integration tests and increase test coverage (#98) 2026-01-05 11:16:55 +01:00
s4n5o6p7q8r9_add_consolidated_at_to_memory_units.py fix: improve mental model consolidation (#197) 2026-01-26 09:54:25 +01:00
t5o6p7q8r9s0_rename_mental_models_to_observations.py chore: internal renames (#204) 2026-01-27 09:53:28 +01:00
u6p7q8r9s0t1_mental_models_text_id.py fix: misc fixes for observations and mental models (#209) 2026-01-27 15:37:57 +01:00
v7q8r9s0t1u2_add_max_tokens_to_mental_models.py fix: misc fixes for observations and mental models (#209) 2026-01-27 15:37:57 +01:00
w8r9s0t1u2v3_fix_mental_models_pk_isolation.py feat: support markdown in reflect and mental models (#307) 2026-02-06 10:49:13 +01:00
x9s0t1u2v3w4_add_bank_config_column.py feat: implement hierarchical configuration (system, tenant, bank) (#329) 2026-02-12 13:14:57 +01:00
y0t1u2v3w4x5_add_result_metadata_gin_index.py fix: improve async batch retain with large payloads (#366) 2026-02-16 12:51:42 +01:00
z1u2v3w4x5y6_add_observation_tags_to_memory_units.py feat: observation_scopes field to drive observations granularity (#447) 2026-02-28 10:46:21 +01:00