Skip to content

Cache searchable_fields to eliminate the extra metadata round-trip on implicit query_by searches #2

@cferrys

Description

@cferrys

Summary

Collection-scoped text searches currently perform an additional GET /collections/{name} call whenever q is present and query_by is omitted, in order to auto-populate query_by from searchable_fields. This creates a hidden extra network round-trip on the hottest path in the client and can materially degrade latency and throughput for search-heavy workloads.

Context

The auto-detection logic exists in both [src/collections.cpp] and [src/search.cpp]. In Collections::search(...) and Search::search(...), the client fetches collection metadata before issuing the actual search request if query_by is missing.

That behavior is convenient, but it is expensive for a high-performance search engine wrapper:

  • A single logical search can become two HTTP requests.
  • Repeated searches against the same collection repeatedly re-fetch identical schema metadata.
  • Recent API additions around collection-scoped search and the like alias make this path more central, so the hidden overhead is more likely to affect normal usage.
  • If the metadata request fails transiently, the client silently loses the optimization and search behavior becomes dependent on an unrelated control-plane call.

This is especially problematic for low-latency services, batch search workloads, and any deployment where the client and server communicate over a network boundary.

Proposed Implementation

  1. Add an internal per-collection cache of searchable_fields, owned by Collections and reused by the search flow.
  2. On the first search without query_by, fetch collection metadata once, derive the comma-separated query_by, and store it in the cache.
  3. Reuse the cached value for subsequent searches against the same collection.
  4. Invalidate or refresh the cache on collection mutation paths such as create, update, and remove.
  5. Keep an escape hatch:
    • either a client option to disable implicit query_by inference entirely, or
    • a dedicated method to prewarm/refresh collection schema metadata explicitly.
  6. Refactor the duplicated inference logic so Search and Collections share one implementation path.

Impact

This removes an avoidable request from a core search path, which should reduce end-to-end latency, cut control-plane load, and improve throughput under sustained search traffic. It also makes client behavior more predictable by separating schema discovery from the execution of the actual query.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions