fleet-memory/hindsight-api/tests
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
..
fixtures rename to hindsight (#2) 2025-11-25 19:28:26 +01:00
__init__.py rename to hindsight (#2) 2025-11-25 19:28:26 +01:00
conftest.py fix: improve claude code and codex for /reflect (#285) 2026-02-04 13:34:45 +01:00
test_admin_backup_restore.py feat: run db migrations offline (optionally) (#114) 2026-01-07 15:49:51 +01:00
test_agents_api.py feat: increase customization for reflect, retain and consolidation (#419) 2026-02-23 20:35:32 +01:00
test_async_batch_retain.py fix: improve async batch retain with large payloads (#366) 2026-02-16 12:51:42 +01:00
test_async_retain_tags.py Add bank-scoped validation to engine and HTTP handlers (#454) 2026-03-02 09:55:21 +01:00
test_base_path.py feat: add reverse proxy support (#346) 2026-02-12 10:09:53 +01:00
test_batch_api.py feat: support Batch API for retain (openai/groq) (#365) 2026-02-16 13:31:50 +01:00
test_batch_api_integration.py feat: support Batch API for retain (openai/groq) (#365) 2026-02-16 13:31:50 +01:00
test_batch_api_validation.py feat: support Batch API for retain (openai/groq) (#365) 2026-02-16 13:31:50 +01:00
test_batch_chunking.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_causal_relations.py feat: implement hierarchical configuration (system, tenant, bank) (#329) 2026-02-12 13:14:57 +01:00
test_causal_relationships.py feat: implement hierarchical configuration (system, tenant, bank) (#329) 2026-02-12 13:14:57 +01:00
test_chunking.py improve retain performances, caching and tests 2025-12-08 18:21:56 +01:00
test_combined_scoring.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_config_validation.py fix: hindsight-embed profiles are not loaded correctly (#316) 2026-02-06 17:13:54 +01:00
test_consolidation.py feat: observation_scopes field to drive observations granularity (#447) 2026-02-28 10:46:21 +01:00
test_custom_embedding_dimension.py feat: add ZeroEntropy reranker provider support (#420) 2026-02-23 10:12:32 +01:00
test_document_tracking.py fix: document not tracked if has 0 extracted facts (#399) 2026-02-18 17:01:57 +01:00
test_entity_labels.py feat: entity labels — optional, free_values, multi_value, UI polish (#450) 2026-03-02 13:05:25 +01:00
test_extensions.py misc: fix vertex/gemini errors and use it for ci tests (#414) 2026-02-20 22:35:38 +01:00
test_fact_extraction_analysis.py feat: implement hierarchical configuration (system, tenant, bank) (#329) 2026-02-12 13:14:57 +01:00
test_fact_extraction_metadata.py feat: include doc metadata in fact extraction (#424) 2026-02-23 11:31:02 +01:00
test_fact_extraction_output_ratio.py feat: implement hierarchical configuration (system, tenant, bank) (#329) 2026-02-12 13:14:57 +01:00
test_fact_extraction_quality.py feat: implement hierarchical configuration (system, tenant, bank) (#329) 2026-02-12 13:14:57 +01:00
test_fact_ordering.py misc: fix vertex/gemini errors and use it for ci tests (#414) 2026-02-20 22:35:38 +01:00
test_file_retain.py feat: accept pdf, images and office files (#390) 2026-02-17 18:15:03 +01:00
test_file_storage_s3.py misc: fix vertex/gemini errors and use it for ci tests (#414) 2026-02-20 22:35:38 +01:00
test_graph_filtering.py feat: filter graph memories with tags (#431) 2026-02-25 10:31:40 +01:00
test_hierarchical_config.py feat: entity labels — optional, free_values, multi_value, UI polish (#450) 2026-03-02 13:05:25 +01:00
test_http_api_integration.py fix: improve async batch retain with large payloads (#366) 2026-02-16 12:51:42 +01:00
test_iris_parser.py feat: add iris as file parser (#395) 2026-02-18 14:09:56 +01:00
test_link_expansion_retrieval.py feat: implement hierarchical configuration (system, tenant, bank) (#329) 2026-02-12 13:14:57 +01:00
test_link_utils.py prepare for release 2025-12-03 11:52:25 +01:00
test_litellm_sdk_cross_encoder.py feat: support litellm-sdk as reranker and embeddings (#357) 2026-02-12 23:53:12 +01:00
test_litellm_sdk_embeddings.py fix: pass encoding_format="float" in LiteLLM embedding calls (#434) 2026-02-25 10:32:05 +01:00
test_llm_provider.py fix: resolve JSON serialization and logging exception propagation in claude_code_llm (#458, #459) (#461) 2026-03-02 10:14:16 +01:00
test_llm_token_metrics.py feat: support for codex and claude-code as llm (#276) 2026-02-02 12:54:44 +01:00
test_llm_tools.py chore: internal renames (#204) 2026-01-27 09:53:28 +01:00
test_load_large_batch.py feat: support for other text and vector search pg extensions (#355) 2026-02-12 14:13:04 +01:00
test_main_module.py fix(python-client): async method parity and server keepalive timeout (#387) 2026-02-17 16:00:14 +01:00
test_mcp_endpoint_routing.py Harden MCP server: fix routing, validation, and usage metering (#341) 2026-02-11 10:41:20 +01:00
test_mcp_extension.py feat: expand MCP tool surface area with 18 new tools and enhanced parameters (#435) 2026-02-25 10:26:46 +01:00
test_mcp_routing.py fix: zeroentropy rerank URL missing /v1 prefix and MCP retain async_processing param (#460) 2026-03-02 10:32:01 +01:00
test_mcp_tools.py feat: configure exposed mcp tools per bank (#439) 2026-02-25 11:57:46 +01:00
test_mental_model_hooks.py Add extension hooks for mental model operations (#260) 2026-01-31 09:30:53 -05:00
test_mental_models.py misc: fix vertex/gemini errors and use it for ci tests (#414) 2026-02-20 22:35:38 +01:00
test_metrics.py chore: remove dead code (#245) 2026-01-30 09:16:32 +01:00
test_mpfp_retrieval.py fix: improve mpfp retrieval (#146) 2026-01-12 18:58:05 +01:00
test_multilingual.py feat: observation_scopes field to drive observations granularity (#447) 2026-02-28 10:46:21 +01:00
test_observation_invalidation.py fix: handle observations regeneration when memories get deleted (#429) 2026-02-24 13:26:33 +01:00
test_observations.py feat: implement hierarchical configuration (system, tenant, bank) (#329) 2026-02-12 13:14:57 +01:00
test_per_operation_llm_config.py feat: add more config options for llm retries (#234) 2026-01-29 17:50:43 +01:00
test_provider_default_models.py feat: switch default model to gpt-4o-mini (#410) 2026-02-19 18:43:52 +01:00
test_query_analyzer.py fix: ci and ui build (#9) 2025-12-03 15:47:53 +01:00
test_recall_chunks_independence.py feat: allow chunks-only in recall (max_tokens=0) (#364) 2026-02-13 16:56:35 +01:00
test_reflect_agent.py fix(reflect): prevent context_length_exceeded on large memory banks (#462) 2026-03-02 12:03:12 +01:00
test_reflect_empty_based_on.py fix: resolve based_on schema/serialization issues in reflect API (#348) 2026-02-12 11:26:12 +01:00
test_reflect_tracing.py feat: add otel traceability (#330) 2026-02-10 12:20:48 +01:00
test_reflections.py feat: improve mental models ux on control plane (#297) 2026-02-04 15:49:03 +01:00
test_reranker_error_handling.py fix: reranker crashes on provider error (#403) 2026-02-19 11:38:37 +01:00
test_retain.py feat: support timestamp="unset" to retain content without a date (#465) 2026-03-02 12:03:23 +01:00
test_schema_isolation.py fix: improve mental model consolidation (#197) 2026-01-26 09:54:25 +01:00
test_search_trace.py feat: extensions (#54) 2025-12-22 11:05:23 +01:00
test_server_module.py fix: improve mental model consolidation (#197) 2026-01-26 09:54:25 +01:00
test_sql_schema_safety.py chore: internal renames (#204) 2026-01-27 09:53:28 +01:00
test_supabase_tenant.py Add Supabase tenant extension as built-in (#267) 2026-02-09 10:16:47 +01:00
test_tags_visibility.py feat: observation_scopes field to drive observations granularity (#447) 2026-02-28 10:46:21 +01:00
test_tei_cross_encoder.py fix: add defensive error handling to PyTorch device detection (#221) 2026-01-28 18:14:54 +01:00
test_temporal_ranges.py feat(mcp): add timestamp to retain (#190) 2026-01-23 16:00:43 +01:00
test_think.py chore: remove dead code (#245) 2026-01-30 09:16:32 +01:00
test_tracing.py misc: fix vertex/gemini errors and use it for ci tests (#414) 2026-02-20 22:35:38 +01:00
test_tracing_integration.py feat: add otel traceability (#330) 2026-02-10 12:20:48 +01:00
test_tracing_spans_verification.py feat: add otel traceability (#330) 2026-02-10 12:20:48 +01:00
test_vertexai_provider.py misc: fix vertex/gemini errors and use it for ci tests (#414) 2026-02-20 22:35:38 +01:00
test_worker.py fix: resolve consolidation deadlock caused by zombie processing tasks on retry (#463) 2026-03-02 11:45:41 +01:00