Skip to main content
This tutorial shows you how to build custom search functionality using the Gloo AI Search API. You’ll learn to authenticate, perform semantic search, work with rich results, and optionally combine search with Completions V2 for Retrieval Augmented Generation (RAG). The Search API gives you full control over how search works in your application — from the query to the UI. Whether you’re building a knowledge base, a chatbot, or a content discovery experience, this tutorial covers the backend patterns you need.
The Discovery Widget in Gloo AI Studio provides a quick, embeddable search experience. This tutorial shows you how to build equivalent functionality using the Search API directly, giving you full control over branding, UI, and integration patterns.

Prerequisites

Before starting, ensure you have:

Working Code Sample

Follow along with complete working examples in all 6 languages (JavaScript, TypeScript, Python, PHP, Go, Java). Includes a proxy server and browser-based frontend for each language.Setup and testing instructions are provided later.
The code snippets in this tutorial are simplified and self-contained — designed for readability and easy copy-paste. The cookbook examples use a modular architecture plus production niceties. Both implement the same APIs and patterns.

Understanding the Search API

The Search API provides AI-powered semantic search across your ingested content. Unlike keyword search, semantic search understands the meaning behind queries — so a search for “secrets to a happy marriage” will find content about “rules for keeping a marriage healthy” even without exact word matches. Endpoint: POST /ai/v1/data/search

Key Features

  • Semantic Search: Near-text search that understands meaning, not just keywords
  • Rich Metadata: AI-generated summaries, biblical analysis, content classifications
  • Snippet Extraction: Pre-chunked content ready for display or RAG
  • Relevance Scoring: Distance, certainty, and score metrics for ranking

Required Parameters

Tenant names are normalized. Spaces are stripped from the publisher name to form the tenant identifier — for example, Example Publisher Name becomes ExamplePublisherName. Passing the raw publisher name with spaces can cause a 400 "invalid tenant" error. To get the exact string, call GET /ai/v1/data/tenant/names and use the value returned.

Optional Parameters

Important: The API’s default certainty is 0.75 when omitted, which is stricter than the Playground’s 0.5. If you’re getting no results, add "certainty": 0.5 to your request to match Playground behavior.

Response Structure

Each result in the data array contains:
Key fields:
  • metadata.certainty — Relevance score (0-1, higher = more relevant)
  • properties.snippet — Content chunk text, ideal for display or RAG context
  • properties.summaries — AI-generated summaries in multiple styles
  • properties.biblical_analysis — Bible references, concepts, and lessons (if applicable)

Test in the Playground First

Before writing code, test your queries in the Search Playground to verify your content is indexed and understand the response structure.
  1. Navigate to Playground in Gloo AI Studio
  2. Select the Search tab
  3. Choose your publisher from the dropdown
  4. Enter a query and review the results
Try it now: Search for a topic covered in your uploaded content. The Playground displays each result with its title, snippet text, and AI-generated insights.

Let’s make a search request with proper authentication. This is the foundation for everything that follows. Each implementation below makes the search request and displays results with titles, types, authors, and relevance scores.

What You’ll See

A successful search returns results with titles, types, and relevance scores:

Key Points

  • Collection must always be "GlooProd"
  • Tenant scopes results to your publisher’s content only
  • certainty: 0.5 matches the Playground default — adjust as needed
  • Request time increases non-linearly with larger limit values

Run the Cookbook Example

The cookbook includes a ready-to-run basic search script for each language:

Step 2: Search + RAG with Completions V2

Search results become even more powerful when used as context for AI-generated responses. This is Retrieval Augmented Generation (RAG) — search for relevant content, then generate an answer grounded in that content.
Two approaches to RAG with Gloo AI:
  • Search API + Completions V2 (this section): Full control over context, prompts, and formatting
  • Grounded Completions: Single API call, simpler but less control
Both retrieve identical content. The difference is who controls how that content is presented to the LLM.

The RAG Workflow

  1. Search — Query the Search API for relevant content
  2. Extract — Pull snippets from results
  3. Format — Build context for the LLM
  4. Generate — Call Completions V2 with the context
  5. Return — Deliver the response with source citations

What You’ll See

The RAG flow searches, extracts context, then generates an AI response grounded in your content:

Run the Cookbook Example

Key Concepts

  • auto_routing: true — Lets Gloo AI automatically select the best model
  • System prompt — Customize to match your use case (tone, format, domain rules)
  • Context formatting — Source labels help the LLM cite correctly
  • Token budget — Keep context concise. 3-5 snippets of ~500 chars each works well

Search + Completions V2 vs Grounded Completions

Both approaches use the same underlying search. Start with Grounded Completions if you want simplicity, then switch to Search + Completions V2 when you need more control.

Try It: Frontend Example

The cookbook includes a browser-based frontend that connects to a proxy server, giving you a visual way to test both search and RAG. The proxy server keeps your credentials secure on the server side.

Architecture

The proxy server exposes two endpoints:
  • GET /api/search?q=<query>&limit=<limit> — Basic search
  • POST /api/search/rag — Search + RAG with Completions V2

Start the Proxy Server

Each language includes a proxy server. Start one:
Then open http://localhost:3000 in your browser.

Search Results

Enter a query and click Search to see results with titles, content types, and relevance scores:
Search results showing content cards with titles, types, and relevance percentages

AI-Powered Answers (RAG)

Click Ask AI to send the same query through the RAG pipeline. The AI generates a response grounded in your search results, with sources listed:
AI response generated from search results with source citations
The frontend is language-agnostic — the same HTML/JS works with any language’s proxy server. This is one approach; customize for your branding and framework.

Complete Working Examples

View Complete Code

Clone or browse the complete working examples for all 6 languages (JavaScript, TypeScript, Python, PHP, Go, Java) with setup instructions, proxy servers, and a browser-based frontend.

What’s Included

Each language implementation provides:
  • auth — Shared API key configuration
  • config — Centralized configuration (URLs, env vars, RAG settings)
  • search_basic — Basic search (CLI script)
  • search_advanced — Advanced search + RAG helpers (CLI script)
  • server — Proxy server exposing REST endpoints for the frontend

Troubleshooting

No Results Returned

  • Missing certainty: Add "certainty": 0.5 to your payload. The API defaults to 0.75 when omitted, which may be too strict.
  • Content not indexed: Test in the Search Playground first. If results appear there but not via API, check your tenant name.
  • Wrong tenant: Results are scoped to your publisher. Verify the tenant name matches your publisher in Organizations. Remember that tenant names are normalized — spaces are stripped (e.g. Example Publisher NameExamplePublisherName). If you’re unsure of the exact string, pull it from GET /ai/v1/data/tenant/names.

403 Forbidden

  • You can only access your own publisher’s content. Other tenant names return 403.
  • A 403 may also mean your API key lacks the gateway permission for the search route (this is a separate permission from grounded completions). Contact support to provision access.
  • Verify your API key is correct and has not been revoked.

Slow Responses

  • Reduce the limit parameter. Request time rises non-linearly with larger result sets.
  • Start with limit=10 and increase only as needed.

Authentication Errors

  • If your API key is rejected, verify it is correct and has not been revoked (see Authentication Tutorial).
  • Ensure you’re using Bearer {api_key} in the Authorization header.

Empty RAG Responses

  • Verify search returns results before calling Completions V2.
  • Use auto_routing: true instead of specifying a model name.

Next Steps

Grounded Completions

Simpler RAG approach — single API call with automatic context management.

Upload Files

Add more content to your Data Engine for richer search results.

Completions V2 API

Full control over LLM interactions with custom prompts and parameters.

Search API Reference

Complete endpoint documentation with request/response schemas.