🔎 Search Context Retrieval

SLM Search Orchestrator

Local search planner that generates query variations, crawls web snippets, and filters/structures contexts offline using Phi-3.5.

🚀 Overview & Capabilities

The SLM Search Orchestrator acts as a pre-retrieval query planner. It expands inputs into 3 targeted terms, crawls DuckDuckGo, and structures raw search snippets into clean markdown segments ready for RAG injection.

💻 Installation

Install the local CPU-optimized package using pip:

Terminal
# Install from PyPI
pip install slm-search-orchestrator

🤖 Truly Agentic Pre-Retrieval Planning

The Search Orchestrator implements an offline planning logic:

  • Query Expansion: Automatically translates raw technical prompts into exactly 3 diverse query terms to cover synonyms and sub-topics.
  • Consolidation & De-duplication: Groups search result snippets, removing redundant links to reduce noise.
  • Off-Grid Fail-safe: Automatically switches to mock local data sources if internet connectivity is missing.

⚡ CPU Performance Tuning Guidelines

Follow these guidelines to optimize retrieval latency:

  • Result Throttling: Set max_results_per_query=2 (default) to limit snippet processing overhead on CPU threads.
  • In-Memory Keep-alive: Avoid re-loading the ONNX session for each search query; keep the orchestrator class instantiated to reuse cache keys.

🎯 Accuracy Improvement Tips

Tip for Query Expansion: Instruct the model to return a strict, parsable JSON array of strings (e.g. ["query_1", "query_2", "query_3"]) without conversational filler.
De-duplication: De-duplicate URLs before routing snippets to RAG models to avoid wasting context tokens on duplicate content.

API Reference

`SLMSearchOrchestrator` Initialization

from slm_search_orchestrator.search_orchestrator import SLMSearchOrchestrator

orchestrator = SLMSearchOrchestrator()
ParameterTypeDescription
model_pathstrLocal path to Phi-3.5 weights. Defaults to "../../models/phi-3.5-mini-instruct-onnx".
system_promptstr | NoneOptional custom system prompt instructions overriding the default template.
user_inputstr | NoneOptional additional user-supplied target parameters or variables.

`retrieve` Method

Expands the query into 3 variations, scrapes search engines, and formats snippets. Include search inputs:

from slm_search_orchestrator.search_orchestrator import SLMSearchOrchestrator

orchestrator = SLMSearchOrchestrator()

# Run query planner and retrieval
result = orchestrator.retrieve("CPU inference thread optimization settings")
print(result)
Retrieved Search Results Output:
[
  {
    "title": "Configuring OMP_NUM_THREADS for CPU Inference",
    "href": "https://docs.slmagents.ai/cpu-threads",
    "body": "For optimal ONNX CPU inference, set OMP_NUM_THREADS to match the physical core count, disabling hyperthreading overhead."
  },
  {
    "title": "Optimizing Local SLM Performance on CPU",
    "href": "https://blog.slmagents.ai/slm-cpu-tuning",
    "body": "Small Language Models run highly efficiently on CPU by mapping threads to core boundaries, keeping memory allocations flat."
  }
]

© 2026 SLM Agents. Built with Apache 2.0 Permissive Open Source License.

🐙 Checkout from GitHub

Clone only this agent's folder from the monorepo using Git sparse-checkout — no need to download the full repository:

Option 1 — Sparse Checkout (Recommended)

Terminal — Git Sparse Checkout
# 1. Create and enter a new directory
$ mkdir slm_search_orchestrator && cd slm_search_orchestrator

# 2. Initialise empty git repo and add remote
$ git init
$ git remote add origin https://github.com/t00114218-stack/SLMAgents.git

# 3. Enable sparse-checkout and set target folder
$ git sparse-checkout init --cone
$ git sparse-checkout set slm_search_orchestrator

# 4. Pull only that agent's source
$ git pull origin main

Option 2 — Full Repository Clone

Terminal — Full Clone
$ git clone https://github.com/t00114218-stack/SLMAgents.git
$ cd SLMAgents/slm_search_orchestrator

💡 Tip: After checkout, install the package locally with pip install -e ./slm_search_orchestrator to run in editable mode without publishing to PyPI.