Act as an expert AI Systems Engineer specializing in LLM-powered web search agents. Analyze the provided GitHub repository focusing exclusively on the web search implementation and its unique search processing patterns.
Required Output:
Search Flow Overview (2-3 sentences)
Key Search Components
Search execution pattern
Query construction approach
Result processing mechanism
Context management method
Search Implementation Steps (numbered, brief)
Query formation
Search execution
Result processing
Context integration
Notable Search Features
Query refinement techniques
Result filtering methods
Context preservation strategies
Search iteration patterns
Prompt and agentic behaver, cheking, tool, extra info ect...
Search-Specific Dependencies
Guidelines:
Focus ONLY on web search functionality
Highlight search processing techniques
Explain context management between searches
Detail query refinement patterns
Describe result cleaning/filtering approaches
Note any search iteration or validation methods
as expert use clear defined techniqual and enginer word/term to be more precis when applicable for consise able for let reboducible/replicae code, if more compact but still clear, use pseudo python code.
Addiotnaly any other special/interesting things.
Please analyze this repository's web search implementation.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
# Search Flow Overview
The web search implementation leverages multiple search engines (Google, Bing, SearXNG, Sogou, ChatGLM) and processes results through a RAG (Retrieval-Augmented Generation) pattern. It refines queries, filters results, integrates context from various sources, and utilizes LLMs for answer generation and related question suggestion.
# Key Search Components
## Search execution pattern:
- **Multi-engine Retrieval:** Queries are dispatched to multiple search engines based on user configuration.
- **Retrieval-Augmented Generation (RAG):** Search results serve as context for LLM interaction, enhancing answer quality.
## Query construction approach:
- **Base Query:** Initially, the user-provided query is used directly.
- **Translated Query (SearXNG - Science Category):** For scientific searches using SearXNG, the query is translated to English via an LLM before execution.
## Result processing mechanism:
- **Content Extraction ([Redacted Person]):** For research mode, URLs from initial search results are fetched and processed by [Redacted Person] to extract full content.
- **Filtering and Limiting:** Results are filtered (e.g., image results by engine) and limited to a configurable number (REFERENCE_COUNT).
## Context management method:
- **Contextual Aggregation:** Search results (snippets or full content), related questions, and image results are combined into a comprehensive context object.
- **Citation Indexing:** Contexts are indexed with [[citation:x]] format for LLM referencing and accurate attribution.
# Search Implementation Steps
1. **Query formation:** User query is received and potentially translated.
2. **Search execution:** Query is executed against selected search engines.
3. **Result processing:** Results are filtered, limited, and optionally enriched with full content extraction. Images are processed separately.
4. **Context integration:** Processed results are formatted with citation indices and integrated into LLM prompts.
# Notable Search Features
## Query refinement techniques:
- **Translation:** Queries are translated to English for scientific searches on SearXNG, improving retrieval effectiveness.
## Result filtering methods:
- **Image Engine Filtering:** Image results are filtered based on selected search engines.
- **Top-K Selection:** Results are limited by `REFERENCE_COUNT` for manageable context size.
## Context preservation strategies:
- **Caching:** Search results are cached based on the query, mode, and categories to reduce latency and resource consumption.
## Search iteration patterns:
- **Related Question Generation:** LLM generates related questions based on initial results, enabling iterative exploration.
## Prompt and agentic behaver, cheking, tool, extra info ect...
- **Deep Reasoning Mode:** A dedicated prompt (DeepQueryPrompt) guides the LLM for in-depth analysis and structured responses in "deep" mode.
- **Research Mode:** A research-specific prompt (ResearchSystemPrompt) and full content extraction via Jina are used for comprehensive analysis. This prompt encourages internal monolog within the LLM for better reasoning.
- **Multi-Modal Responses:** Images are retrieved and presented alongside text-based answers and related questions.
- **Dynamic Prompts:** Prompts are constructed dynamically incorporating context, citations, and mode-specific instructions.
# Search-Specific Dependencies
- `fetch-sse`: For handling Server-Sent Events (SSE) for streaming responses.
- `cheerio`: For web scraping and result parsing from search engine responses.
- `jina`: For full-text extraction from web pages in research mode.