Skip to content

feat: optional query log for LeannSearcher (#70)#325

Open
raoabinav wants to merge 2 commits into
yichuan-w:mainfrom
raoabinav:feat/log-queries-issue-70
Open

feat: optional query log for LeannSearcher (#70)#325
raoabinav wants to merge 2 commits into
yichuan-w:mainfrom
raoabinav:feat/log-queries-issue-70

Conversation

@raoabinav
Copy link
Copy Markdown
Contributor

@raoabinav raoabinav commented May 20, 2026

Closes #70.

LeannSearcher reads LEANN_QUERY_LOG from the environment on init. When set, each call to search() appends a JSON line to that file with the query text, the query embedding (when one was computed, pure-BM25 paths skip it), top_k, and the result id/score pairs. Failures appending get logged at WARNING and don't break the search.

raoabinav and others added 2 commits May 20, 2026 10:43
Closes yichuan-w#70.

LeannSearcher reads LEANN_QUERY_LOG from the environment on init. When set,
each call to search() appends a JSON line to that file with the query text,
the query embedding (when one was computed — pure-BM25 paths skip it),
top_k, and the result id/score pairs. Failures appending are logged and
don't break search.

The format is jsonl, append-only, no rotation. Off by default — has to be
explicitly opted in via the env var, so existing callers aren't affected.

I went with an env var rather than a CLI flag because the issue framed
this as a researcher use case and env-var fits "set it once for the session,
forget about it". Happy to add a --log-queries CLI flag too if that's
preferred.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CI's ty caught that `open(self._query_log_path, ...)` is invalid because
`self._query_log_path` is typed `Optional[str]` and `open()` doesn't accept
None. The runtime guard `if self._query_log_path:` at the call site doesn't
narrow inside the called method.

Local variable narrows the type cleanly. Runtime behavior unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.

[Feature] Log query under index for further research

1 participant