Skip to content

feat(index): debug-log query type, latency and result count in query() - #750

Merged
vishal-bala merged 1 commit into
redis:mainfrom
jackiectl2:feat/query-timing-debug-log
Oct 13, 2026
Merged

vishal-bala merged 1 commit into
redis:mainfrom
jackiectl2:feat/query-timing-debug-log

Conversation

@jackiectl2

@jackiectl2 jackiectl2 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #494

What

SearchIndex.query() and AsyncSearchIndex.query() now emit a single DEBUG record on the redisvl.index.index logger after each query:

Index <name> executed <QueryClass> in <x.xx> ms (<n> results)
  • Covers every query type routed through query() (BaseQuery subclasses, AggregationQuery, HybridQuery, SQLQuery). For CountQuery, the logged count is the returned total.
  • Only the query class name is logged, never the query string or params (which can carry user text or vectors).
  • The record is only built when DEBUG is enabled; otherwise the overhead is a single time.perf_counter() call. Query results and behavior are unchanged.

Out of scope / possible follow-up: the optional slow-query warning threshold from the issue (left out to avoid adding new configuration surface without agreement on where it should live), and instrumenting paginate/batch_query.

Testing

  • New unit tests in tests/unit/test_query_timing_log.py (sync, async, CountQuery, and no record above DEBUG); no Redis needed.
  • make format, make check-sort-imports, make check-types, codespell: clean.
  • make test locally against redis:8.4: same results as main plus the 4 new passing tests. Tests that download the default HuggingFace vectorizer fail with a proxy error on both main and this branch (environment).
  • Ran the query/search/aggregation/hybrid/SQL integration tests with --log-level=DEBUG to exercise the new log path against real Redis.

Suggested label: auto:minor


Note

Low Risk
Observability-only change on the query path; no API or result semantics changes, with minimal overhead when DEBUG is off.

Overview
SearchIndex.query() and AsyncSearchIndex.query() now record wall time with time.perf_counter() and, when DEBUG is enabled on the redisvl.index.index logger, emit one line per call: index name, query class name only (e.g. VectorQuery, CountQuery), elapsed milliseconds, and result count.

Logging is centralized in _log_query_timing on the shared index base class. CountQuery uses the returned integer as the count instead of len(). Query strings, filters, and vectors are never written to the log. Above DEBUG, behavior and return values are unchanged aside from the timing call.

Unit tests in test_query_timing_log.py cover sync/async vector queries, count queries, and the absence of records at INFO, using a stubbed search so Redis is not required.

Reviewed by Cursor Bugbot for commit babcf5c. Bugbot is set up for automated code reviews on this repo. Configure here.

Emit one DEBUG record from SearchIndex.query() and AsyncSearchIndex.query()
with the index name, query class, elapsed milliseconds and result count.
Only the query class name is logged, never the query string or params, and
the record is only built when DEBUG is enabled. CountQuery results (an int)
are logged as the count.

Fixes redis#494

Signed-off-by: Tianlang (Jackie) Chen <305351710+jackiectl2@users.noreply.github.com>
@vishal-bala vishal-bala added the auto:internal Changes only affect the internal API label Oct 13, 2026
@vishal-bala
vishal-bala self-requested a review October 13, 2026 14:55

@vishal-bala vishal-bala left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

@vishal-bala
vishal-bala merged commit a0e75a4 into redis:main Oct 13, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:internal Changes only affect the internal API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add query timing and debug logging to index execution paths

2 participants