Implementation:24kchengYe MemoMind patch hindsight
| Knowledge Sources | |
|---|---|
| Domains | Software_Engineering, Deployment |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
External tool for applying MemoMind-specific patches to the pip-installed hindsight-api package by overwriting files in site-packages with patched versions from the patches/ directory.
Description
The patch_hindsight.py script customizes the pip-installed hindsight-api package by copying modified files from the `patches/` directory over the installed package files. Each patch:
- Backs up the original: copies the installed file to `.orig` (only on first run)
- Overwrites with the patch: copies the patched file from `patches/` to the installed location
Patches applied:
- fact_extraction.py: occurred_start fallback logic
- fact_storage.py: Windows strftime %-d fix
- orchestrator.py: original_document_id tracking
- link_expansion_retrieval.py: super-entity filtering (copied from engine/ version)
- consolidation_prompts.py: language preservation rule
- consolidator.py: skip trivial observations, lower similarity threshold
- hindsight/server.py: 600s startup timeout for CUDA model loading
The Docker build bakes patches into the image. The `PATCHES.md` file documents each patch and its rationale.
Usage
Run this script after installing hindsight-api in a virtualenv. It is also run automatically during the Docker build.
Code Reference
Source Location
- Repository: MemoMind
- File: patch_hindsight.py
- Lines: L15-86 (patch_file at L15-32, patch_link_expansion at L34-49, main at L51-83)
Signature
def patch_file(src_name, dst_rel_path) -> bool:
"""Copy a patched file from patches/ to the installed package."""
def patch_link_expansion() -> bool:
"""Copy the custom link_expansion_retrieval.py with super-entity filtering."""
def main():
"""Apply all patches to the installed hindsight-api package."""
Import
# Run as a script: python patch_hindsight.py [venv_path]
# Default venv_path: D:\pythonPycharms\memomind-env
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| venv_path | str | No | Virtual environment path (default: D:\pythonPycharms\memomind-env) |
| patches/ | directory | Yes | Directory containing patched files |
Outputs
| Name | Type | Description |
|---|---|---|
| count | int | Number of files patched |
| .orig files | backup | Original files backed up as .orig |
Usage Examples
Applying Patches
# Install hindsight-api first
pip install hindsight-api-slim
# Apply MemoMind patches
python patch_hindsight.py /path/to/venv
# Output:
# MemoMind Patch Script
# Venv: /path/to/venv
# Patches: /path/to/patches
# Target: /path/to/venv/Lib/site-packages/hindsight_api
#
# Backed up engine/retain/fact_extraction.py -> .orig
# PATCHED engine/retain/fact_extraction.py
# ...
# Done: 7 files patched.