Skip to content

Ship offline LanceDB search for agent docs - #977

Draft
stale2000 wants to merge 6 commits into
mainfrom
stale2000/agent-docs-search
Draft

stale2000 wants to merge 6 commits into
mainfrom
stale2000/agent-docs-search

Conversation

@stale2000

@stale2000 stale2000 commented Oct 5, 2026 •

Copy link
Copy Markdown

Summary

comfy-cli[docs-search] installs a version-matched companion package with a 59.3 MiB compressed offline search pack: 337 documentation chunks, precomputed 384-dimensional BGE vectors, the pinned local ONNX query encoder and tokenizer, and a LanceDB BM25 index. The base CLI remains lightweight and keeps its existing local BM25 search.

comfy docs status reports available retrieval modes. docs search --mode auto selects hybrid retrieval when the matching pack is installed; bm25, semantic, and hybrid can also be selected explicitly. Search output includes the backend, retrieval mode, source section, corpus and model identity, confidence evidence, and fallback reason. docs show reads the cited section. Searches use packaged assets and do not download a model; absent or incompatible optional assets leave auto mode on core BM25, while explicit semantic/hybrid requests return a structured error.

The bundled comfy skill teaches shell-capable agents to search, read relevant sections, and reformulate a missed query once before answering from retrieved sources. This exposes the workflow through the CLI; it does not add native tools to the separate local Comfy-agent runtime.

The release workflow builds and validates the data package alongside comfy-cli, then smoke-installs the optional extra from PyPI. PyPI trusted publishing needs to be configured for both package names before release.

Example output

The following is the exact stdout from the hybrid search command against wheels built from the source distributions, run outside the checkout:

$ comfy --json docs search 'A job is still pending and seems frozen, what should I check?' --mode hybrid --limit 1
{"schema": "envelope/1", "type": "envelope", "ok": true, "command": "docs search", "version": "0.0.0", "where": null, "data": {"query": "A job is still pending and seems frozen, what should I check?", "results": [{"id": "comfy-debug:job-stuck-triage", "title": "comfy-debug agent guide", "headings": ["Job-stuck triage"], "source": "comfy_cli/skills/comfy-debug/SKILL.md", "source_line": 128, "excerpt": "If a prompt seems to hang:\n\n```\n# 1. Is it still tracked?\ncomfy --json jobs ls\n\n# 2. What does the server think?\ncomfy --json jobs status <prompt_id>\n\n# 3. Watch live events (NDJSON, one per line)\ncomfy --json-stream jobs watch <prompt_id>\n```\n\nThree possible answers:\n\n| Symptom | Likely cause | Fix |\n|---|---|---|\n| `status: pending`, `queue_position > 0` | Earlier jobs ahead of you | Wait or cancel them |\n| `status: running` but no progress events | A long sampler step, or a hung custom node | Wait one sampler-step's worth; if still stuck, interrupt |\n| `status: error` with no `error_message` | Server crashed mid-execution | Check the Comfy Cloud dashboard or server logs (cloud), or the stdout of `comfy launch` (local) |", "score": 0.032786883413791656, "score_type": "rrf"}], "zero_hit": false, "has_more": true, "search_backend": "lancedb-hybrid-rrf", "retrieval_mode": "hybrid", "corpus_hash": "1d62f56018524ac95c81a250666f0f4405c545328e6670b7b338ecb3a17af519", "pack_version": "0.0.0", "model": "BAAI/bge-small-en-v1.5", "fallback_reason": null, "highest_vector_similarity": 0.7049703896045685, "fts_term_coverage": 0.75, "query_mode": "hybrid"}, "error": null}

Ship the CLI's selected guides and bundled agent skills as a searchable
offline corpus. Expose bounded search results and section retrieval through
the standard JSON envelope so an agent can retrieve only the guidance it needs.

Constraint: Keep search offline and add no runtime dependency.
Rejected: Add embeddings in the first release | model/runtime cost is not justified before evaluating lexical search
Confidence: high
Scope-risk: moderate
Directive: Update docs/search-sources.json and regenerate the corpus when an indexed source changes.
Tested: 57 focused docs, discovery, and schema tests; Ruff lint and format; corpus freshness; wheel and sdist-built wheel smoke checks outside the checkout
Not-tested: Full suite after schema registration fix; five failures in unchanged terminal-rendering, TLS-root, and bounded workflow tests reproduced individually
@coderabbitai

coderabbitai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Agents need to find relevant CLI guidance even when a user describes a problem without knowing the command or heading. A version-matched optional LanceDB pack keeps BM25, semantic, and reciprocal-rank hybrid retrieval local while the base CLI retains its dependency-light lexical search. The bundled skill teaches agents to search, inspect source sections, and reformulate a missed query.

Constraint: Preserve the Python 3.10+ platform matrix and keep the optional native dependencies out of base installs

Rejected: Download the encoder on first search | searches must work offline from packaged assets

Confidence: high

Scope-risk: moderate

Directive: Keep the query encoder revision paired with the precomputed vectors and rebuild the pack when the corpus or model changes

Tested: 74 focused tests; ruff check; generated corpus/pack checks; core and companion wheels/sdists built and rebuilt from sdists; installed wheel hybrid search smoke

Not-tested: Four unrelated full-suite failures remain in deploy-progress rendering, pretty-print styling, and HTTP certificate handling; PyPI publishing trust for the companion distribution requires repository setup
@stale2000 stale2000 changed the title Add offline documentation search for agents Ship offline LanceDB search for agent docs Oct 6, 2026
@socket-security

socket-security Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedonnxruntime@​1.23.27410010010070
Addedonnxruntime@​1.24.374100100100100
Addedpyarrow@​24.0.086100100100100
Addedlancedb@​0.25.098100100100100
Addedtokenizers@​0.23.2100100100100100

View full report

Upstream changed reviewed documentation sources after the search branch was created. Merge the current default branch so the generated corpus and its version-matched LanceDB pack stay compatible with the PR merge tree.

Constraint: Pull-request CI checks the corpus against the merged default branch

Rejected: Exclude the new upstream guidance from this pack | the CLI corpus should describe the current release

Confidence: high

Scope-risk: narrow

Directive: Regenerate both the core corpus and LanceDB pack whenever an included upstream source changes

Tested: Conflict-free merge and fresh corpus/pack checks

Not-tested: GitHub checks are rerunning after push
The latest default-branch merge added source sections that agents should be able to find. Regenerate the canonical corpus so its hash matches the packaged LanceDB vectors and FTS index.

Constraint: The docs-search pack must match the core corpus hash exactly

Rejected: Keep the previous corpus snapshot | search status would report the shipped pack as incompatible

Confidence: high

Scope-risk: narrow

Directive: Rebuild the companion pack when this generated corpus changes

Tested: docs bundle --check, docs pack --check, and 74 focused tests

Not-tested: Full suite has four failures in untouched deploy-progress, pretty-print, and HTTP certificate tests
Windows Git checkout may translate generated JSON line endings even when the corpus content is unchanged. Normalize only CRLF during the freshness comparison so the three-platform docs-search matrix checks the same generated content.

Constraint: Docs-search CI runs on Windows with Python 3.10

Rejected: Remove the freshness check from Windows | cross-platform corpus reproducibility is part of the feature

Confidence: high

Scope-risk: narrow

Tested: 75 focused docs-search and CLI tests; ruff check; corpus and LanceDB pack checks

Not-tested: The earlier Windows CI attempt also exposed unrelated console-codepage failures; the matrix now runs in Python UTF-8 mode and needs a fresh run
The source_line field in the docs output contract identifies the section heading. Store that same anchor in LanceDB chunks so search results and docs show point to the same source location, including chunks split past the encoder window.

Constraint: Search and show must preserve the established one-based heading-line contract

Rejected: Return the first body line or chunk offset | it disagrees with the section ID and show location

Confidence: high

Scope-risk: narrow

Directive: Keep chunk source metadata aligned with the preview schema when changing chunking

Tested: 75 focused docs-search/CLI tests; rebuilt and checked the pack; verified live hybrid search and show both report line 128

Not-tested: New GitHub checks are pending after push

This branch has not been deployed

No deployments
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.

1 participant