XMem icon indicating copy to clipboard operation
XMem copied to clipboard

Add v2 S3 original storage and hybrid search

Open ishaanxgupta opened this issue 5 months ago β€’ 15 comments

Summary

  • Add v2-only original preservation to S3 with deterministic object keys and original_chunk vector IDs
  • Run original preservation in parallel with v2 memory extraction, including bounded batch/concurrency controls
  • Add v2-only /v2/memory/hybrid-search returning extracted memory hits plus indexed original chunks
  • Add configurable env/settings knobs and tests for preservation + hybrid search

Testing

  • .venv/bin/python -m pytest tests/unit/test_original_storage.py tests/api/test_v2_hybrid_search.py
  • .venv/bin/python -m pytest tests/api/test_memory_versioning.py tests/api/test_dependencies_and_routes.py tests/integration/test_retrieval_pipeline.py
  • .venv/bin/python -m pytest tests/api
  • .venv/bin/python -m ruff check src/storage/original.py src/api/routes/v2/memory.py src/api/routes/v2/workflows.py src/api/routes/v2/activities.py src/api/schemas.py src/config/settings.py tests/unit/test_original_storage.py tests/api/test_v2_hybrid_search.py
  • .venv/bin/python -m py_compile src/storage/original.py src/api/routes/v2/memory.py src/api/routes/v2/workflows.py src/api/routes/v2/activities.py src/api/schemas.py src/config/settings.py

ishaanxgupta avatar Jun 03 '26 15:06 ishaanxgupta

Fails
:no_entry_sign:

πŸ” This PR modifies sensitive files: src/config/settings.py. These require review by a core maintainer (@ishaanxgupta or @ved015) before merging.

Warnings
:warning:

πŸ“¦ This PR changes 1017 lines (additions + deletions). Large PRs are harder to review thoroughly β€” consider splitting it.

Messages
:book:

βœ… Targeting main. Please squash commits before merging to keep the git history clean.

Generated by :no_entry_sign: dangerJS against 0b79b8d261f5373076dc616734b4466add3c5197

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

βœ… Staging Deployment Report

Item Value
Branch amazon_s3
Commit 209eed7
Environment Staging
Health http://3.6.255.148:8001/health
API Docs http://3.6.255.148:8001/docs
Smoke Tests success

🟒 Staging is live and healthy! Test your changes at the staging URL above.

Ready to ship? Comment /promote on this PR to merge to main and deploy to production.

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

πŸ” API Schema Diff

---REPORT---


Auto-generated by API Schema Diff workflow

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

βœ… Staging Deployment Report

Item Value
Branch amazon_s3
Commit 5b512db
Environment Staging
Health http://3.6.255.148:8001/health
API Docs http://3.6.255.148:8001/docs
Smoke Tests success

🟒 Staging is live and healthy! Test your changes at the staging URL above.

Ready to ship? Comment /promote on this PR to merge to main and deploy to production.

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

πŸ” API Schema Diff

---REPORT---


Auto-generated by API Schema Diff workflow

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

βœ… Staging Deployment Report

Item Value
Branch amazon_s3
Commit 7c3f2a9
Environment Staging
Health http://3.6.255.148:8001/health
API Docs http://3.6.255.148:8001/docs
Smoke Tests success

🟒 Staging is live and healthy! Test your changes at the staging URL above.

Ready to ship? Comment /promote on this PR to merge to main and deploy to production.

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

πŸ” API Schema Diff

---REPORT---


Auto-generated by API Schema Diff workflow

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

βœ… Staging Deployment Report

Item Value
Branch amazon_s3
Commit 65a8733
Environment Staging
Health http://3.6.255.148:8001/health
API Docs http://3.6.255.148:8001/docs
Smoke Tests success

🟒 Staging is live and healthy! Test your changes at the staging URL above.

Ready to ship? Comment /promote on this PR to merge to main and deploy to production.

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

πŸ” API Schema Diff

---REPORT---


Auto-generated by API Schema Diff workflow

github-actions[bot] avatar Jun 03 '26 15:06 github-actions[bot]

@greptileai

ishaanxgupta avatar Jun 03 '26 15:06 ishaanxgupta

@greptileai review this PR

ishaanxgupta avatar Jun 03 '26 15:06 ishaanxgupta

@greptileai review

ishaanxgupta avatar Jun 03 '26 15:06 ishaanxgupta

Greptile Summary

This PR adds v2-only original document preservation to S3 with deterministic object keys and indexed original chunks in the vector store, plus a new /v2/memory/hybrid-search endpoint that combines extracted memory results with raw-chunk results in a single response.

  • src/storage/original.py implements S3 upload and concurrent vector-store chunk indexing with replay-safe deterministic IDs; config is snapshotted into the Temporal payload at workflow start.
  • MemoryIngestWorkflow and MemoryBatchIngestWorkflow are updated to launch original-storage in parallel with the extraction pipeline, with bounded concurrency and configurable fail-open/fail-closed behavior.
  • hybrid_search_memory_v2 fans out across requested memory domains and, when original storage is enabled, appends filtered vector-store results for indexed chunks.

Confidence Score: 3/5

Two correctness issues need fixing before merging: the single-item workflow leaks a background Temporal activity task after failure, and the new hybrid-search endpoint calls the pipeline accessor outside its error-handling scope.

The single-item MemoryIngestWorkflow creates an asyncio Task for original storage but has no finally/except path to cancel it when a downstream activity fails, causing background Temporal activity dispatch for dead-lettered jobs. Separately, hybrid_search_memory_v2 calls get_retrieval_pipeline() before its try/except block without a require_ready guard, producing unstructured 500s on pipeline init failure.

src/api/routes/v2/workflows.py (MemoryIngestWorkflow error path) and src/api/routes/v2/memory.py (hybrid_search_memory_v2 pre-try pipeline call)

Important Files Changed

Filename Overview
src/api/routes/v2/workflows.py Adds parallel original-storage task to both single-item and batch ingest workflows. Single-item workflow leaks the original_task asyncio Task when a non-high-effort activity fails β€” the task is never cancelled in the except handler, causing background Temporal activity dispatch for dead-lettered jobs.
src/api/routes/v2/memory.py Adds hybrid-search endpoint and original-storage config injection. The hybrid_search endpoint calls get_retrieval_pipeline() before the try/except block without a require_ready dependency guard, producing unstructured 500s if the pipeline is not ready.
src/storage/original.py New module implementing S3 upload and vector-store chunk indexing for raw originals. Deterministic S3 keys and vector IDs make the operation replay-safe. Well-structured with bounded concurrency controls.
src/api/routes/v2/activities.py Adds memory_store_original_activity Temporal activity that delegates to preserve_original. Straightforward; correctly registers the activity in ALL_ACTIVITIES.
src/api/schemas.py Adds HybridSearchRequest and HybridSearchResponse Pydantic models. Domain validation and field constraints follow the same pattern as the existing SearchRequest.
src/config/settings.py Adds ~30 new settings fields for original storage and hybrid search, all with sensible defaults. Also adds aws_session_token for temporary-credential support.

Fix All in Cursor Fix All in Codex Fix All in Claude Code

Reviews (2): Last reviewed commit: "Address Greptile review feedback" | Re-trigger Greptile

greptile-apps avatar Jun 03 '26 16:06 greptile-apps

βœ… Staging Deployment Report

Item Value
Branch amazon_s3
Commit e55e801
Environment Staging
Health http://3.6.255.148:8001/health
API Docs http://3.6.255.148:8001/docs
Smoke Tests success

🟒 Staging is live and healthy! Test your changes at the staging URL above.

Ready to ship? Comment /promote on this PR to merge to main and deploy to production.

github-actions[bot] avatar Jun 03 '26 16:06 github-actions[bot]

πŸ” API Schema Diff

---REPORT---


Auto-generated by API Schema Diff workflow

github-actions[bot] avatar Jun 03 '26 16:06 github-actions[bot]