Implementation:666ghj BettaFish FirstSearchNode run
| Knowledge Sources | |
|---|---|
| Domains | NLP, Information_Retrieval, LLM_Prompting |
| Last Updated | 2026-10-08 00:00 GMT |
Overview
Concrete node that generates an initial search query from a paragraph's title and content using an LLM, shared across all three search engine pipelines.
Description
The FirstSearchNode is a BaseNode that takes a paragraph's title and content (from the report structure) and calls an LLM to generate a targeted search query with reasoning. This node initiates the research loop for each paragraph by translating the paragraph's descriptive content into an actionable search query. The system prompt instructs the LLM to produce JSON output containing `search_query` and `reasoning` fields.
Usage
Import this node when you need to generate a search query from a paragraph outline. It runs as the first step in each paragraph's research loop, before the search tool is called and before the FirstSummaryNode processes results.
Code Reference
Source Location
- Repository: BettaFish
- Files:
- `InsightEngine/nodes/search_node.py:L21-151`
- `MediaEngine/nodes/search_node.py:L21-151`
- `QueryEngine/nodes/search_node.py:L21-151`
Signature
class FirstSearchNode(BaseNode):
def __init__(self, llm_client):
"""
Args:
llm_client: LLMClient - OpenAI-compatible LLM client
"""
def run(self, input_data: Any, **kwargs) -> Dict[str, str]:
"""
Call LLM to generate a search query from paragraph title/content.
Args:
input_data: dict with 'title' and 'content' keys
(or JSON string of same)
Returns:
Dict with 'search_query' (str) and 'reasoning' (str)
"""
Import
from InsightEngine.nodes import FirstSearchNode # or MediaEngine/QueryEngine
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input_data | str | Yes | Contains 'title' and 'content' keys from report structure |
Outputs
| Name | Type | Description |
|---|---|---|
| search_query | str | LLM-generated search query for the paragraph |
| reasoning | str | LLM's reasoning for why this query is appropriate |
Usage Examples
Generate Search Query
from InsightEngine.nodes import FirstSearchNode
from InsightEngine.llms import LLMClient
llm = LLMClient(api_key="sk-...", model_name="moonshot-v1-8k", base_url="https://api.moonshot.cn/v1")
node = FirstSearchNode(llm)
# Input from ReportStructureNode
paragraph = {"title": "技术发展现状", "content": "分析AI技术在教育领域的最新进展"}
result = node.run(paragraph)
print(result["search_query"]) # e.g., "AI教育技术 2024 最新进展"
print(result["reasoning"]) # e.g., "搜索最新AI教育技术发展动态"