Skip to content

feat: add pluggable file search storage foundation - #483

Merged
franciscojavierarceo merged 11 commits into
mainfrom
codex/file-search-core
Nov 3, 2026
Merged

franciscojavierarceo merged 11 commits into
mainfrom
codex/file-search-core

Conversation

@franciscojavierarceo

@franciscojavierarceo franciscojavierarceo commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add typed file, vector-store, and search contracts; pluggable FileSearchRepository and FileBlobStore interfaces; portable SQL metadata and bounded exact retrieval; and local blob storage. Store listing batches current attachment counts and usage. Durable, token-fenced cleanup intents cover uploads and deletions; expired leases cannot let a publisher expose missing content. Recovery retains abandoned-upload tombstones for later sweeps when a delayed write finishes after an initial cleanup pass. Local staging is addressable by file ID, and cancellation drains publication before cleanup. This is the independently compilable foundation of the file-search stack; HTTP routes and periodic cleanup are in #485. CI uses the macOS 15 Apple Silicon runner because GitHub is retiring macOS 14 and its scheduled brownout canceled wheel validation.

Review order: #483 → #484 → #485 → #486 → #34. PostgreSQL vector indexing remains in follow-up #278.

Test Plan

  • cargo test --offline -p agentic-server-core --test file_search_service: 31 passed, 1 PostgreSQL test ignored locally. Includes two-service upload/recovery interleavings, restart recovery after metadata rejection plus failed blob removal, delayed-staging cancellation, and a late-write/failed-rollback regression.
  • cargo test --offline -p agentic-server-core --lib storage::local_files::tests: 5 passed, including absent-directory and deterministic staging cleanup.
  • cargo test --offline -p agentic-server-core --lib storage::schema::tests: 6 passed, 4 PostgreSQL tests ignored locally; PostgreSQL CI exercises the final schema.
  • cargo clippy --offline --all-targets -- -D warnings, cargo fmt -- --check, and repository pre-commit hooks: passed.
  • The official OpenAI Python SDK HTTP integration test is in feat: expose Files and vector-store HTTP APIs #485 and passed locally against the rebuilt final stack.

Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>
Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>
Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>

# Conflicts:
#	crates/agentic-server-core/tests/prompt_cache_breakpoints_test.rs
#	crates/agentic-server/tests/responses/prompt_cache_breakpoints.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Blob cleanup cannot be retried after metadata deletion fails to remove the blob, and listing stores incurs excessive sequential queries from per-store metadata and count lookups.

2 open issues
What changed in this PR

Adds the core storage foundation for file search, supporting later HTTP APIs and Responses tool execution without exposing either in this layer.

Changes:

  • Introduces typed file-search contracts and injectable repository/blob providers.
  • Implements portable SQL persistence, local blob storage, bounded ingestion, and exact retrieval.
  • Adds schema readiness checks and regression coverage for persistence, cancellation, filtering, and ingestion limits.
File Description
crates/​agentic-server-core/​tests/​file_search_service.rs Tests service lifecycle, retrieval, providers, and failure handling.
crates/​agentic-server-core/​src/​types/​mod.rs Exports file-search types.
crates/​agentic-server-core/​src/​types/​file_search/​id.rs Validates generated file IDs.
crates/​agentic-server-core/​src/​types/​file_search/​filter.rs Validates and evaluates attribute filters.
crates/​agentic-server-core/​src/​types/​file_search/​config.rs Defines storage and embedding configuration.
crates/​agentic-server-core/​src/​types/​file_search.rs Defines typed requests, results, errors, and validation.
crates/​agentic-server-core/​src/​tool/​mod.rs Exports the file-search module.
crates/​agentic-server-core/​src/​tool/​file_search/​service/​setup.rs Constructs providers and checks index identity.
crates/​agentic-server-core/​src/​tool/​file_search/​service/​files.rs Implements upload, content retrieval, and deletion.
crates/​agentic-server-core/​src/​tool/​file_search/​service.rs Coordinates vector-store lifecycle, ingestion, and search.
crates/​agentic-server-core/​src/​tool/​file_search/​ranking.rs Implements cosine, keyword, and hybrid ranking.
crates/​agentic-server-core/​src/​tool/​file_search/​provider.rs Defines provider contracts and default adapters.
crates/​agentic-server-core/​src/​tool/​file_search/​mod.rs Exports service and provider interfaces.
crates/​agentic-server-core/​src/​tool/​file_search/​ingest.rs Adds bounded text/PDF extraction and token chunking.
crates/​agentic-server-core/​src/​tool/​file_search/​embeddings.rs Implements bounded embedding calls and response validation.
crates/​agentic-server-core/​src/​storage/​schema/​readiness.rs Checks file-search tables and required permissions.
crates/​agentic-server-core/​src/​storage/​schema.rs Extends schema validation and supervisor readiness tests.
crates/​agentic-server-core/​src/​storage/​mod.rs Exports SQL and local-file storage modules.
crates/​agentic-server-core/​src/​storage/​local_files.rs Implements durable local blob publication and bounded reads.
crates/​agentic-server-core/​src/​storage/​file_search.rs Adds transactional SQL persistence and bounded corpus loading.
crates/​agentic-server-core/​migrations/​0008_file_search.sql Creates file-search tables, relationships, and an index.
crates/​agentic-server-core/​Cargo.toml Adds ingestion dependencies and optional PDF support.
Cargo.lock Locks the added dependencies.

Review effort: Balanced

Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Failed upload cleanup can leave unrecoverable orphaned blobs, while insufficiently durable deletion commits can restore metadata after its blob has been permanently removed.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve cleanup intent when metadata rollback and blob removal fail

crates/​agentic-server-core/​src/​tool/​file_search/​service/​files.rs:58

[P2] If metadata publication rolls back and files.remove also fails, this branch leaves uploaded bytes with neither a file row nor a cleanup marker. The caller never receives the generated ID, and even deletion with that ID returns 404, so the service cannot reclaim the orphan after restart. Persist recoverable upload/cleanup intent until publication or rollback cleanup is resolved, and add a regression combining metadata rejection with FailOnceBlobs.

2 resolved since last review

Review effort: Balanced

Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Reconciliation can delete an active upload’s blob before metadata commits, allowing the upload to report success with permanently missing content.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Interrupted uploads leave staging files that cleanup ignores

crates/​agentic-server-core/​src/​storage/​local_files.rs:63

[P2] A crash after staging-file creation but before unlinking leaves .upload-{id}-{uuid} bytes on disk. Reconciliation removes only the final file-ID path and clears the marker, so repeated interrupted uploads can exhaust the volume despite successful cleanup. Persist or rediscover staging paths and reclaim them only after establishing that their publication is inactive.

1 resolved since last review

Review effort: Balanced

Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>
@franciscojavierarceo
franciscojavierarceo requested a balanced review from Copilot October 30, 2026 21:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Renewal-failure cleanup can leave orphaned staging files without cancelling and draining publication, while full-directory scans on every deletion cause quadratic cleanup costs.

2 open issues
3 resolved since last review

Review effort: Balanced

Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Recovery can clear cleanup intent before an expired uploader’s late write completes, leaving a permanently untracked orphan if rollback removal fails.

1 open issue
2 resolved since last review

Review effort: Balanced

Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to weigh the identified ranking-correctness, deletion-race, and pagination-scalability risks.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>
franciscojavierarceo and others added 2 commits November 1, 2026 23:11
Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>
@franciscojavierarceo
franciscojavierarceo merged commit 61e3b2e into main Nov 3, 2026
17 checks passed
franciscojavierarceo added a commit that referenced this pull request Nov 6, 2026
## Summary

Add a `FileSearchRepository` backed by sqlite-vec for semantic cosine
retrieval on a file-backed SQLite database. It keeps portable SQL
metadata and published-chunk visibility, normalizes embeddings before
indexing, and records a provider identity so stores cannot silently
switch indexes. Keyword and hybrid search continue through the bounded
exact ranker. SQLite metadata and vector rows now publish in one
transaction, so concurrent replicas cannot remove a winning attachment.
Orphan cleanup rechecks rows under a writer lock and immediately
reclaims stale rows and per-store tables; search skips empty stores and
unpublished rows, and uses bounded exact ranking when sqlite-vec's
4,096-candidate limit is exceeded. The loadable extension path is
deployment-controlled; #485 wires its configuration.

BEIR-sized corpus testing exposed the old 64 MiB serialized-corpus limit
and top-k edge cases with duplicate chunks and near ties. This branch
keeps the default exact-search limit at 64 MiB and gives sqlite-vec a
256 MiB limit, validates vector-index coverage, and adaptively fetches
candidates to preserve the requested document count.

Review order: #483 → #484 → #485 → #486 → #34. PostgreSQL vector
indexing remains in #278.

## Test Plan

- Review follow-up: the portable vector map is migration-owned;
extension-specific index SQL lives in
`storage/file_search/sqlite_vec_index.rs`, publication has one
implementation, and writes use `BEGIN IMMEDIATE` without a process-wide
mutex. Focused storage and schema tests passed; the original 3
sqlite-vec integration tests passed, including immediate orphan-row and
orphan-table recovery.
- `SQLITE_VEC_EXTENSION_PATH=/tmp/vec0.so cargo test -p
agentic-server-core --test sqlite_vec_repository -- --ignored`: 4 passed
in CI with sqlite-vec 0.1.9, covering publication, extreme finite
embeddings, restart, filtered and duplicate-chunk search, deletion,
concurrent attachment conflicts, unpublished rows, empty stores, and
searches beyond the 4,096-candidate limit.
- `cargo test -p agentic-server-core --lib`: 1,370 passed, 6 ignored.
`cargo clippy -p agentic-server-core --all-targets -- -D warnings`,
`cargo fmt -- --check`, and pre-commit hooks passed.
- Maral's capacity regression: a new sqlite-vec integration test
publishes a serialized store above 64 MiB, then exercises keyword,
hybrid, and filtered semantic searches against it. The Rust CI run
passed this test and the full ignored sqlite-vec integration suite.
- CI downloads the pinned Linux sqlite-vec release asset, verifies its
SHA-256, and runs the ignored integration tests.

### BEIR retrieval evidence (2026-11-03, benchmark commit `fd6b574`)

Compared the provider's semantic search with [OGX's published
vector-mode
results](https://ogx-ai.github.io/docs/building_applications/rag_benchmarks).
Used the official BEIR **test** corpora, queries, and relevance
judgments, title + body text, `cl100k_base` 512-token chunks with
128-token overlap, `nomic-ai/nomic-embed-text-v1.5` embeddings, and
top-10 document scoring with `pytrec_eval`. The 512/128 setting comes
from [OGX's documented benchmark
config](https://ogx-ai.github.io/docs/building_applications/rag_benchmarks),
but this was a local preparation, not [OGX's full API ingestion
path](https://github.com/ogx-ai/ogx/tree/12a51077cdd4f89b16df5eb6de12a88b0bfcf7df/benchmarking/rag).
A local harness loaded the prepared chunks into the actual
`SqliteVecRepository` and called its `search` method for every judged
query. sqlite-vec 0.1.9 ran on CPU.

| Dataset | Documents / chunks / queries | nDCG@10 OGX vector → ours |
Recall@10 OGX vector → ours | MAP@10 OGX vector → ours |
| --- | ---: | ---: | ---: | ---: |
| NFCorpus | 3,633 / 4,921 / 323 | 0.3106 → **0.3101** | 0.1482 → 0.1462
| 0.1153 → 0.1137 |
| SciFact | 5,183 / 6,604 / 300 | 0.6943 → **0.6968** | 0.8369 → 0.8296
| 0.6442 → 0.6496 |
| ArguAna | 8,674 / 9,278 / 1,406 | 0.3765 → **0.3928** | 0.7610 →
0.8037 | 0.2542 → 0.2624 |

All 2,029 searches succeeded. An independent exhaustive NumPy cosine
calculation on the same embeddings gave identical aggregate nDCG@10 for
SciFact and ArguAna; NFCorpus differed by 0.000084. This validates
sqlite-vec against an exact-cosine oracle on our prepared vectors. The
proximity to OGX's published vector scores is indicative, not exact
parity: OGX's current batch ingestion path applies whitespace cleaning
and appears to use 800/400-token file-processor defaults for automatic
chunking, despite the benchmark config documenting 512/128. The
published run does not include materialized chunk/embedding or per-query
result fixtures, so its exact input and rankings cannot yet be compared.

**Scope and limit:** This is a repository-level semantic retrieval test
with prepared embeddings; it does not exercise the Files/Vector Stores
HTTP APIs, automatic ingestion, hybrid reranking, Responses
`file_search`, or end-to-end answer generation. OGX's fourth BEIR
dataset, FiQA, produces 63,129 chunks and exceeds this branch's
10,000-chunk corpus bound, so full four-dataset parity remains
unvalidated.

---------

Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>
franciscojavierarceo added a commit that referenced this pull request Nov 7, 2026
## Summary

Expose the Files and vector-store upload, lifecycle, attachment, and search routes over the pluggable core service. Add server configuration for local file bytes, embeddings, and an optional trusted sqlite-vec extension path. Wire the routes into authentication and OpenAPI, with deployment documentation. Reconcile abandoned blob cleanup intents at startup and periodically while the gateway runs. Local routes enforce the configured API key and request-body ceiling; deletion tolerates a cleanup marker already removed by reconciliation, and startup logs provider setup diagnostics. This layer does not register the Responses `file_search` built-in tool.

Review order: #485 → #486 → #34. #483 and #484 are merged. PostgreSQL vector indexing remains in #278.

## Test Plan

- `cargo test -p agentic-server --test file_search_http_test`: 6 passed, including missing, incorrect, and valid API-key cases and configured multipart/JSON body limits.
- `cargo test -p agentic-server-core --test file_search_service`: 32 passed, 1 ignored, including the deletion cleanup-marker race regression.
- Full workspace `cargo test --offline` passed on the restacked #34 head containing these fixes.
- `cargo test -p agentic-server --lib openapi`: 19 passed.
- `cargo test -p agentic-server --bin agentic-server config_file::tests`: 37 passed.
- `cargo build --offline -p agentic-server --bin agentic-server` and `cargo clippy --offline -p agentic-server -p agentic-server-core --all-targets -- -D warnings`: passed.
- `openai==3.8.0` client E2E: upload, list/retrieve/content, vector-store attachment, filtered search, detach, and deletion passed against the rebuilt local gateway. The Rust CI job runs this script.
- Formatting and repository pre-commit hooks passed on signed-off commits. CI also runs PostgreSQL file-search persistence, sqlite-vec, and bounded PDF ingestion checks.
- OpenAI reference cassette parity for Files and vector-store routes remains unverified: this environment has no OpenAI API credential. The focused local gateway HTTP suite and OpenAI SDK client E2E cover the route lifecycle; no reference cassette was hand-authored.


Signed-off-by: Francisco Javier Arceo <4163062+franciscojavierarceo@users.noreply.github.com>
franciscojavierarceo added a commit that referenced this pull request Nov 8, 2026
## Summary

Register and execute the Responses `file_search` built-in tool through the existing typed gateway tool loop. The handler searches the configured file-search service, keeps retrieved passages private for model continuation, exposes `file_search_call.results` only when requested, and restores typed file citations in completed and streamed output. This is the top layer of a smaller stack; the Files and vector-store APIs, provider contracts, SQLite-vec adapter, and protocol types are reviewed below it.

Review order: #483 (storage contracts and portable SQL/local providers) → #484 (SQLite-vec) → #485 (Files and vector-store HTTP APIs and provider configuration) → #486 (Responses protocol and stream lifecycle) → this PR. The existing PostgreSQL/pgvector follow-up is #278; later retrieval and lifecycle work remains stacked above it.

The storage service accepts injected `FileSearchRepository` and `FileBlobStore` implementations. The lower layers configure SQLite-vec for semantic retrieval; Milvus and remote blob stores remain adapter extension points.

## Test Plan

- `cargo test -p agentic-server-core --test file_search_tool_test`: 6 passed, covering blocking and streaming calls, citations, opt-in results, mixed client tools, failures, and selector validation.
- `cargo test -p agentic-server-core --lib`: 1,385 passed, 6 ignored on the corrected, restacked file tree. Full workspace `cargo test --offline` also passed on that tree.
- Changed-crate all-target Clippy with warnings denied, formatting, and all-file pre-commit hooks passed on the corrected, restacked file tree.
- The failing Rust CI check at `33b20ba` came from an output-item test fixture missing the typed `logprobs: []` field. The corrected citation projection test passes locally; CI is running on the cleanly restacked head.
- SQLite-vec review fixes from #484 are carried through the stack: atomic publication, safe orphan cleanup, empty/unpublished row handling, and exact fallback above sqlite-vec's candidate limit.

Signed-off-by: Francisco Javier Arceo <arceofrancisco@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants