Skip to main content
The rag_search tool is the cornerstone of information retrieval within the UBIK platform. It allows agents to perform Retrieval-Augmented Generation (RAG) searches across your uploaded documents. Unlike a standard keyword search, this tool uses semantic understanding to find the most relevant “chunks” of text from your knowledge base and uses a Large Language Model (LLM) to synthesize a precise answer grounded in those facts.

When to Use This Tool

Use rag_search when you need to:
  • Answer specific questions based on your private data (e.g., “What is the vacation policy?”).
  • Find specific facts buried in large documents.
  • Verify information against a trusted source.
  • Retrieve context to support a conversation.
This tool is optimized for retrieval accuracy and grounded generation. It is not intended for processing entire documents or generating long-form summaries (use information_analysis for that).

Input Parameters

The tool accepts the following parameters:

Scoping & Permissions

The rag_search tool automatically respects the security context of the execution:
  • User Access: Searches documents owned by the user or shared with them via workspaces.
  • Session Context: If running within a chat session, it includes documents attached to that specific session.
  • External ID: For multi-tenant applications, it strictly enforces external_user_id boundaries, ensuring users never see data from other tenants.

Output Structure

The tool returns a structured object containing the answer, the evidence used to generate it, and metadata about the execution.

Retrieving Chunk Details

The rag_search response provides chunk_ids in the contexts array. You can use these IDs to fetch precise location data for highlighting or deep-linking within the original document using the GET /chunks/{chunk_id} endpoint. The response structure adapts to the content modality (Text/PDF vs. Audio/Video):

Streaming Events

When used in streaming mode, the rag_search tool emits real-time events via SSE (Server-Sent Events). This allows you to track the progress of the RAG pipeline and display the answer as it is generated.

Event Types

Pipeline Phases (tool_update)

The tool_update event contains a data field with a phase and a status. Here are the possible phases:
  1. SEARCH_PREPARATION
    • status: started
    • Indicates that the pipeline has started and is preparing the search.
  2. RETRIEVAL
    • status: completed
    • data: { "retrieved_count": <int> }
    • Indicates that the initial vector search is complete and how many documents were found.
  3. RERANKING
    • status: completed
    • data: { "initial_count": <int>, "reranked_count": <int>, "kept_count": <int> }
    • Indicates that results have been re-ranked by relevance. kept_count is the number of documents kept for generation.
  4. COMPILING_RESULTS (Generation)
    • status: started
    • Indicates that the LLM generation of the answer is starting.

Content Streaming (tool_partial_update)

During the generation phase, tool_partial_update events are emitted for each generated text fragment.
  • content: <string> (The text fragment)
  • output_key: "response"
These fragments must be concatenated to form the complete answer.
Handling Large Events (Chunking)If an event payload exceeds the SSE size limit, it will be split into multiple _delta_sse events. For detailed instructions and code examples on how to buffer and reconstruct these chunked events, please refer to the Streaming Results Guide or the Agent Session Events Guide.

Example Event Flow

Searching across all available knowledge. Input:
Searching only within a specific technical manual. Input:

Multimodal Capabilities

The rag_search pipeline is fully multimodal. If you have indexed documents containing images (like PDFs with charts or slides), the search can retrieve relevant visual context.
  • Text-to-Image Retrieval: Your text query can match descriptions of images.
  • Image Understanding: The generation model can “see” the retrieved images to answer questions about charts, diagrams, or photos.
Activation RequiredMultimodal RAG is not enabled by default. To activate this feature for your workspace, please contact the UBIK team at contact@ubik-agent.com.
For a deeper dive into how the pipeline handles embeddings, re-ranking, and hybrid search, see the RAG Pipeline Deep Dive.