Skip to navigation

search

View as MarkdownOpen in Claude

Perform a hybrid search combining vector similarity, keyword matching, filename search, and metadata search. Candidates from all strategies are merged, scored, filtered, and ranked.

The search pipeline works in three stages:

  1. Candidate collection — run vector, filename, metadata, and keyword searches in parallel
  2. Scoring — combine signals using max-signal-wins with agreement boosts
  3. Ranking — apply diversity penalties, exact-match boosts, and tag filtering

Parameters

query_vector
list[float]Required

Embedding vector for the query, produced by encoding the query text with the same model used to build the index.

enhanced_text
strRequired

Preprocessed query text for keyword and full-text search. Typically the output of preprocess_query().

count
intDefaults to 3

Maximum number of results to return.

similarity_threshold
floatDefaults to 0.0

Minimum combined score for a result to be included. Results below this threshold are filtered out.

tags
list[str] | NoneDefaults to None

Filter results to only those containing at least one of the specified tags.

keyword_weight
float | NoneDefaults to None

Accepted for API compatibility and currently ignored. Scoring is always max-signal-wins with an agreement boost, so setting this has no effect on the results.

original_query
str | NoneDefaults to None

The original unprocessed query string. Used for exact-match boosting.

Returns

list[dict] — A list of result dictionaries, each containing:

  • content (str) — the chunk text
  • score (float) — the final combined score
  • metadata (dict) — chunk metadata including filename, section, tags
  • search_type (str) — the primary search strategy that found the result

Example

from signalwire.search import SearchEngine, preprocess_query
engine = SearchEngine(backend="sqlite", index_path="./docs.swsearch")
enhanced = preprocess_query("How do I configure an agent?", vector=True)
results = engine.search(
query_vector=enhanced["vector"],
enhanced_text=enhanced["enhanced_text"],
count=5,
original_query="How do I configure an agent?",
)
for result in results:
print(f"[{result['score']:.3f}] {result['metadata']['filename']}")
print(f" {result['content'][:120]}...")