The QueryStrategy class represents a search strategy for a specific channel. It encapsulates the query template, channel type, and relevance scoring used to execute targeted searches across different data sources.This is an internal model used by the research engine to generate and execute search queries. While you typically won’t instantiate this class directly, understanding its structure helps you understand how the engine generates search strategies based on your research goals.
Score indicating the expected relevance of this strategy to the research goal. Higher scores indicate strategies that are more likely to produce relevant results.Range: Typically 0.0-1.0, but not strictly enforcedUsage: Used internally to prioritize or weight results from different strategiesDefault:1.0
Builds the final search query by substituting template placeholders with actual company information.
def build_query(self, company_domain: str) -> str: """ Build a concrete search query from the template. Args: company_domain: The company domain to search for (e.g., "stripe.com") Returns: The final search query with placeholders substituted """
Strategies are automatically generated by the QueryGenerator service based on your research goal and search depth. Here’s how the engine uses QueryStrategy:
from app.services import QueryGeneratorfrom app.models.search import QueryStrategy# Generate strategies based on research goalquery_generator = QueryGenerator()strategies: list[QueryStrategy] = await query_generator.generate_strategies( research_goal="Find companies using React and GraphQL", search_depth="standard")print(f"Generated {len(strategies)} strategies")# Example strategies that might be generated:for strategy in strategies: print(f"Channel: {strategy.channel}") print(f"Template: {strategy.query_template}") print(f"Relevance: {strategy.relevance_score}") print()
# Jobs search uses generic queries without company-specific placeholdersstrategy = QueryStrategy( channel="jobs_search", query_template="Senior Backend Engineer Golang Kubernetes")# Returns template unchangedquery = strategy.build_query("anycompany.com")# Result: "Senior Backend Engineer Golang Kubernetes"# This searches across all companies' job postings,# then filters results to match the target domain
# Web search uses domain to scope resultsstrategy = QueryStrategy( channel="web_search", query_template="site:{DOMAIN} engineering blog infrastructure")query = strategy.build_query("stripe.com")# Result: "site:stripe.com engineering blog infrastructure"# This searches only within the company's domain
# GitHub search uses organization namestrategy = QueryStrategy( channel="github_search", query_template="org:{COMPANY_NAME} language:typescript stars:>100")query = strategy.build_query("netflix.com")# Result: "org:netflix language:typescript stars:>100"# Company name extracted: "netflix" from "netflix.com"
# News search uses company name for broader coveragestrategy = QueryStrategy( channel="news_search", query_template="{COMPANY_NAME} announces new technology stack")query = strategy.build_query("shopify.com")# Result: "shopify announces new technology stack"
When creating custom strategies (if extending the engine):
Use specific, targeted queries rather than broad terms
Include channel-appropriate operators (e.g., site: for web, org: for GitHub)
Set relevance scores based on expected precision and recall
Test queries manually before deploying to production
Show Performance Optimization
Strategies are immutable, so they can be cached and reused
The engine executes strategies in parallel across companies
Higher relevance scores don’t affect execution order but may influence result ranking
Consider the cost/benefit of each channel when designing strategies
Show Debugging Strategies
To debug strategy execution:
# Log the actual queries being executedfor strategy in strategies: for domain in company_domains: query = strategy.build_query(domain) print(f"[{strategy.channel}] {domain}: {query}")
This helps identify:
Malformed queries
Incorrect placeholder substitution
Channel-specific issues
Show Custom Channels
If implementing custom search channels:
Follow the naming convention: {source}_search
Document which placeholders are supported
Handle edge cases in company name extraction (e.g., multi-part domains)
Set appropriate relevance scores based on channel quality