Skip to content

Memory: vendor localvector + add vector_search_enabled flag (phase 1) - #164

Merged
FMXExpress merged 2 commits into
mainfrom
claude/vector-search-onboarding
Jun 6, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/vector-search-onboarding

Conversation

@FMXExpress

@FMXExpress FMXExpress commented Jun 6, 2026 •

Copy link
Copy Markdown
Owner

Closing — pivoting to fork-in-place per maintainer feedback. The config flag + onboarding question parts of this PR are folding into the new PR alongside the in-tree port of localvector's source files; no make get-localvector step, no vendor/localvector/, PasClaw owns the code with MIT attribution preserved in each ported file's header.

Replacement PR will follow shortly off main.

Lay the groundwork for hybrid FTS5 + local-vector memory_search.
Picoclaw and nanobot both fuse keyword (FTS5 BM25) and semantic
(local embeddings) ranking via Reciprocal Rank Fusion; PasClaw's
memory_search has been FTS5-only since it landed. localvector
(FMXExpress/localvector, MIT) ships the Object Pascal pieces we
need — sqlite-vec wrapper, FTS5 + vec0 hybrid store, ONNX-runtime'd
BERT embedder (MiniLM / bge), Reciprocal Rank Fusion, auto-provision
for the ONNX runtime DLL and embedding model weights.

This commit is intentionally phase 1: vendor + opt-in flag +
operator-facing prompt. No runtime wiring yet; the IMemoryIndex
backend that actually USES localvector lands in a follow-up so the
ONNX Runtime / sqlite-vec deps (the ~300MB of model weights, the
embed-on-write code path, the tests that need the DLLs available)
don't all turn up in one PR.

Adds:

  Makefile  — `make get-localvector` clones the upstream into
              vendor/localvector, same shape as `make get-indy`.
              vendor/ is already in .gitignore so cloning doesn't
              pollute the working tree. LOCALVECTOR_REPO /
              LOCALVECTOR_DIR env-overridable for forks.

  Config    — TConfig.VectorSearchEnabled: Boolean, default True.
              JSON key "vector_search_enabled". Round-trip rule
              mirrors RenderMarkdown: default-on so stock configs
              stay tidy, written explicitly only when operator set
              it to False (so the off-state sticks across reloads).

  Onboard   — new PromptVectorSearch(Cfg) section, ordered after
              PromptVaultTools just before SaveConfig. Mirrors the
              existing default-yes pattern (Enter / 'y' / 'yes'
              all enable; anything else disables). Honest about
              the deferred runtime: prompt explicitly says "model
              download deferred until first memory_search" so
              operators answering yes today don't sit waiting for
              a download that won't fire until the runtime PR
              lands.

  README    — extend the memory_search row to mention the new
              opt-in vector mode + deferred provisioning.

Phase 2 (next PR) wires localvector's IVectorStore behind a new
PasClaw.Memory.Vector unit that implements IMemoryIndex; tools.Memory
picks the hybrid backend when VectorSearchEnabled is True.

Phase 3 (after that) wires localvector's OrtProvision + VecProvision
to fetch the ONNX Runtime DLL + sqlite-vec extension + chosen
embedding model on first memory_search call, with a clear progress
indicator and graceful degrade-to-FTS5 if any piece fails.

Verified:
  - make build clean.
  - make get-localvector clones into vendor/localvector successfully.
  - Default VectorSearchEnabled = True.
  - ToJSON writes "vector_search_enabled":false only when explicitly
    disabled (default-on state stays tidy).
  - FromJSON round-trips both true and false correctly.
  - Missing key in JSON keeps the default (True).
  - Full test suite green: smoke + hashline + toolview +
    anthropic-server-tools + openai-server-tools + println-helper +
    utf8-codepage-tag + gemini-schema-strip + markdown-render +
    json-utf8-roundtrip.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47b18e7727

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Makefile Outdated
@if [ ! -d $(LOCALVECTOR_DIR) ]; then \
mkdir -p $(dir $(LOCALVECTOR_DIR)); \
echo "Cloning localvector into $(LOCALVECTOR_DIR)..."; \
git clone --depth 1 $(LOCALVECTOR_REPO) $(LOCALVECTOR_DIR); \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor LOCALVECTOR_REF when cloning localvector

When a maintainer sets the documented LOCALVECTOR_REF to pin a tested localvector revision, this recipe still clones the remote default HEAD because the variable is never referenced. I checked git clone -h: -b/--branch is the option that checks out a non-HEAD branch/ref, while --depth 1 here only makes the default-branch clone shallow, so attempted reproducible vendoring silently uses whatever upstream currently publishes.

Useful? React with 👍 / 👎.

PR #164's get-localvector recipe documented "Pin via
LOCALVECTOR_REPO=... LOCALVECTOR_REF=... env when we need a
specific revision" but the recipe itself never referenced
LOCALVECTOR_REF — a maintainer setting it would silently clone the
remote default-branch HEAD instead. Reproducible vendoring broken.

Wire LOCALVECTOR_REF through the recipe in a shape that handles all
three forms a maintainer might pass — branch, tag, or commit SHA:

  REF empty  (default)  shallow `git clone --depth 1`. Fast/small.
                        Same shape as the original recipe.
  REF set               full `git clone`, then `git -C ... checkout
                        $(LOCALVECTOR_REF)`. Two-step because:
                        - `git clone --branch` accepts branches and
                          tags but rejects arbitrary SHAs.
                        - `--depth 1` makes a follow-up checkout
                          fail for anything outside the latest
                          depth-1 commit.
                        Full clone is the only shape that handles
                        all three forms.

Verified:
  - LOCALVECTOR_REF empty (default) → shallow clone of HEAD, same
    as before.
  - LOCALVECTOR_REF=<commit-sha> → full clone, then HEAD checks out
    to exactly that SHA. (Tested: pinned to localvector's current
    HEAD via its rev-parse, post-clone `git rev-parse HEAD` matches.)
  - LOCALVECTOR_REF=does-not-exist → checkout fails loudly with
    "pathspec 'does-not-exist' did not match any file(s) known to
    git" and `make` exits non-zero. No silent fallback to HEAD.
  - Full test suite green: smoke + hashline + toolview +
    anthropic-server-tools + openai-server-tools + println-helper +
    utf8-codepage-tag + gemini-schema-strip + markdown-render +
    json-utf8-roundtrip.

INDY_REF intentionally NOT added — the Indy recipe never claimed to
support a pin variable, so there's no broken-promise to fix there.
A separate PR can extend INDY_REF symmetrically if anyone needs
reproducible Indy vendoring.
@FMXExpress
FMXExpress merged commit 38c5d2f into main Jun 6, 2026
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
PR FMXExpress#164 vendored localvector via `make get-localvector` cloning into
`vendor/localvector`. Maintainer feedback was that for a core feature
we shouldn't be coupled to an external repo at build time and the
vendor tree shipped things we don't use. Pivot to fork-in-place:
PasClaw owns the source under src/pkg/memory/localvector/ with the
upstream MIT LICENSE preserved alongside it and a per-file header
naming the source commit (0f00eec) for change tracking.

Removed
-------
  - Makefile: `make get-localvector`, `LOCALVECTOR_DIR`,
    `LOCALVECTOR_REPO`, `LOCALVECTOR_REF`, the localvector vendoring
    comment block, the `get-localvector` .PHONY entry.
  - The vendoring approach as a whole. `vendor/localvector` was
    transitional and never committed (it was always under the
    gitignored `vendor/` prefix); nothing to delete in tree.

Brought in-tree (src/pkg/memory/localvector/)
---------------------------------------------
  LICENSE                                — verbatim MIT from upstream
  LocalVector.VectorStore.pas            — IVectorStore + RRF + chunker
  LocalVector.VectorStore.Sqlite.pas     — FPC backend (dynamic sqlite3
                                           + vec0 + FTS5)
  LocalVector.VectorStore.FireDAC.pas    — Delphi backend (FireDAC +
                                           vec0 + FTS5)
  LocalVector.Sqlite3.pas                — minimal dynamic sqlite3
                                           binding (needed for
                                           load_extension)
  LocalVector.Embedder.pas               — ONNX inference + pooling
  LocalVector.Tokenizer.pas              — BERT WordPiece
  LocalVector.Models.pas                 — embedding model registry
  LocalVector.Runtime.pas                — runtime info
  LocalVector.OrtProvision.pas           — ONNX Runtime DLL load /
                                           auto-download (win-x64)
  LocalVector.VecProvision.pas           — sqlite-vec extension
                                           load / auto-download
  LocalVector.Downloader.pas             — generic HTTP fetch helper
  onnxruntime.pas                        — ONNX Runtime C API wrapper
  onnxruntime_pas_api.pas                — ONNX Runtime C API binding

Excluded: `LocalVector.App.pas` (the standalone CLI app — PasClaw is
the consumer here, not the CLI).

Each .pas file carries an attribution header pointing at the upstream
URL + the exact source commit so we can diff against upstream for
later bug-fix pulls without a submodule.

New unit: src/pkg/memory/PasClaw.Memory.Vector.pas

  Implements the IMemoryIndex contract over the in-tree IVectorStore
  + TEmbedder + TBertTokenizer. Open() locates the sqlite-vec
  extension, the chosen embedding model, the BERT vocab, and the ONNX
  Runtime under `$PASCLAW_HOME/cache/localvector/`. Each missing piece
  returns False with a single debug-level log line; no exception leaks
  to the caller — so PasClaw.Tools.Memory can fall through to the
  FTS-only NewMemoryIndex without an agent-visible stack trace.

  Default model is MiniLM (DEFAULT_MODEL from LocalVector.Models —
  384-d, ~90 MB). A config knob can expose bge / mxbai later. Search
  fuses FTS5 + vec0 ranks via Reciprocal Rank Fusion (k=60) inside
  the localvector store and returns chunk text as snippet.

  SyncDir is full-rebuild-per-call for now (embedding is fast enough
  for typical memory dirs; mtime-tracked incremental sync is a
  follow-up).

Updated: src/pkg/tools/PasClaw.Tools.Memory.pas

  Tool_MemorySearch reads `Cfg.VectorSearchEnabled` (the flag PR FMXExpress#164
  landed). When True, tries NewVectorMemoryIndex first; on Open()
  False, falls through to the existing NewMemoryIndex (FTS-only).
  Separate DB files (.index.db vs .index.db.vec) so flipping the flag
  doesn't cross-talk between the two schemas. Both backends live
  alongside each other on disk; only one is opened per call.

Makefile

  src/pkg/memory/localvector added to UNIT_DIRS so `LocalVector.*` and
  `onnxruntime*` units resolve at compile time. No new build deps —
  ONNX Runtime + sqlite-vec are dynamically loaded at runtime, not
  linked. A stock build with no `$PASCLAW_HOME/cache/localvector/`
  artifacts still runs; vector search just stays inert until the
  runtime is provisioned.

README

  memory_search row updated: the hybrid mode is no longer "after the
  runtime hookup PR lands" — it's wired now; only the runtime
  artifacts under $PASCLAW_HOME/cache/localvector/ have to be present
  for the vector half to engage.

Verified
--------
  - `make` clean on Linux/FPC. The in-tree localvector units compile,
    link into the binary, drag no new build-time deps in.
  - NewVectorMemoryIndex.Open returns False quietly on a system with
    no artifacts under <home>/cache/localvector — no exception, no
    error to the user. Tools.Memory falls through to FTS as designed.
  - NewMemoryIndex still works the same — the FTS5 fallback is
    unchanged.
  - Full test suite green: smoke + hashline + toolview +
    anthropic-server-tools + openai-server-tools + println-helper +
    utf8-codepage-tag + gemini-schema-strip + markdown-render +
    json-utf8-roundtrip.

Supersedes
----------
PR FMXExpress#164 stayed merged on main since it landed the config flag +
onboarding prompt (both still useful). This PR removes the now-unused
vendoring tooling that PR FMXExpress#164 also added.
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