Skip to main content
Lesson 13 of 16 · Collections, RAG & Files

The Hybrid RAG Pattern with Grok

Lesson 13 of 16 Updated July 29, 2026 Developer
On this page
  1. Combine All Information Sources
  2. Pattern Architecture
  3. What Each Source Contributes
  4. How a Hybrid Request Unfolds
  5. Three Situations Where the Pattern Shines
  6. Key Takeaways

Combine All Information Sources

Hybrid RAG—Retrieval-Augmented Generation—is the most advanced pattern in the Grok ecosystem. Its principle: stop deciding upfront where the answer lies. Your internal collections, web search, X search, and code execution are all made available in a single request, and the model decides which ones to solicit based on the question asked. You no longer build conditional branches; you open doors.

4
Combinable Sources
Auto
Tool Selection
Dual
Internal + Web Citations
Async
Native Python SDK

Pattern Architecture

Technically, it all comes down to the tools list: you declare several tools without specifying an order or condition.

response = await client.responses.create(
    model="grok-4.5",
    input="Compare our internal documentation with market best practices for API authentication.",
    tools=[
        {
            "type": "collections_search",
            "collection_ids": [collection_id]
        },
        {"type": "web_search"},
        {"type": "x_search"},
        {"type": "code_interpreter"}
    ]
)

Given this question, Grok will likely fetch your documentation from the collection, run a web search on authentication best practices, then synthesize the two in a comparative response. The other two tools remain unused: nothing in the question calls for X user opinions or a Python calculation. This selection is the heart of the pattern, and it explains why declaring an extra tool costs nothing as long as it isn’t relevant.

What Each Source Contributes

collections_search opens access to your internal knowledge bases: private technical documentation, policies and procedures, contracts and legal documents, customer support base. This is the only source containing what the model cannot know otherwise—your company reality.

web_search covers the public space. You find what you don’t control and that changes: regulations and official standards, vendor technical documentation, news, market comparison points. This is the natural complement to collections, which only become outdated when you update them.

x_search queries X and provides access to a different kind of material: real-time opinions and feedback, technology trends, reactions to a recent announcement, general market sentiment. You enable it when the question concerns what people think, not what is written.

code_interpreter finally executes Python in a sandbox. It calculates on data the other tools just extracted, produces a chart, transforms a dataset, or verifies that a code snippet works. This is the only tool that produces new information rather than retrieving it.

How a Hybrid Request Unfolds

When multiple tools are available, execution always follows the same flow. Grok starts by analyzing the question to determine which sources serve it, queries internal collections, searches externally on the web or X when necessary, then synthesizes everything into a coherent response, and finally attaches its citations. These distinguish internal references, prefixed collections://, from external references in https://—so you know reading the response which claim comes from your documents and which comes from elsewhere.

Three Situations Where the Pattern Shines

In competitive intelligence, a question like “How do our competitors handle client onboarding?” mobilizes all three documentary sources at once: the collection describes your own onboarding journey, the web provides articles and studies on market practices, X brings raw user feedback from people who just experienced onboarding with a competitor.

In compliance, “Is our data policy compliant with the latest EU regulation?” requires holding two texts side by side: your current policy, stored in the collection, and the regulatory text in force, retrieved from the web. Neither suffices alone, and this is exactly the case where the manual approach becomes painful.

Finally, in technical support, “How do I resolve this timeout error in our API?” combines your internal troubleshooting guides with forums, Stack Overflow, and the framework’s official documentation. The agent gets in one response what it would have searched for in two tabs and a wiki.

Key Takeaways

  • The hybrid RAG pattern combines internal collections, web, X, and code in a single request
  • Grok automatically chooses the relevant tools based on the question
  • The four tools are: collections_search, web_search, x_search, code_interpreter
  • Citations distinguish internal sources (collections://) from web sources (https://)
  • This pattern is ideal for cases requiring cross-referencing internal and external sources