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:- A Gloo AI Studio account
- Your Client ID and Client Secret from the API Credentials page
- Your Tenant (publisher) name from Organizations in Studio
- Content uploaded to the Data Engine (see Upload Files Tutorial)
- Authentication setup — Complete the Authentication Tutorial first
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.
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/data/v1/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
| Parameter | Description |
|---|---|
query | The search query string |
collection | Always "GlooProd" |
tenant | Your publisher (tenant) name |
limit | Number of results to return (10-100 recommended) |
Optional Parameters
| Parameter | Type | Description |
|---|---|---|
certainty | float (0-1) | Minimum relevance threshold. The Search Playground defaults to 0.5. We recommend starting with 0.5 and adjusting as needed. |
Response Structure
Each result in thedata array contains:
metadata.certainty— Relevance score (0-1, higher = more relevant)properties.snippet— Content chunk text, ideal for display or RAG contextproperties.summaries— AI-generated summaries in multiple stylesproperties.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.- Navigate to Playground in Gloo AI Studio
- Select the Search tab
- Choose your publisher from the dropdown
- Enter a query and review the results
Step 1: Basic Search
Let’s make a search request with proper authentication. This is the foundation for everything that follows. Each implementation below handles token management, 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.5matches the Playground default — adjust as needed- Request time increases non-linearly with larger
limitvalues
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
The RAG Workflow
- Search — Query the Search API for relevant content
- Extract — Pull snippets from results
- Format — Build context for the LLM
- Generate — Call Completions V2 with the context
- 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
| Search + Completions V2 | Grounded Completions | |
|---|---|---|
| Control | Full control over context, prompts, ordering | Gloo handles context automatically |
| Complexity | More code, more flexibility | Single API call |
| Custom prompts | Yes — any system prompt | Limited customization |
| Context formatting | You control structure and ordering | Gloo optimizes automatically |
| Best for | Custom UX, domain-specific needs | Quick prototyping, standard Q&A |
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
GET /api/search?q=<query>&limit=<limit>— Basic searchPOST /api/search/rag— Search + RAG with Completions V2
Start the Proxy Server
Each language includes a proxy server. Start one:http://localhost:3000 in your browser.
Search Results
Enter a query and click Search to see results with titles, content types, and relevance scores:
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:
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 OAuth2 token management with automatic refreshconfig— 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.5to your payload. The API defaults to0.75when 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
tenantname. - Wrong tenant: Results are scoped to your publisher. Verify the tenant name matches your publisher in Organizations.
403 Forbidden
- You can only access your own publisher’s content. Other tenant names return 403.
- Verify your Client ID and Client Secret are correct and not expired.
Slow Responses
- Reduce the
limitparameter. Request time rises non-linearly with larger result sets. - Start with
limit=10and increase only as needed.
Authentication Errors
- Tokens expire. Implement token refresh logic (see Authentication Tutorial).
- Ensure you’re using
Bearer {token}in the Authorization header.
Empty RAG Responses
- Verify search returns results before calling Completions V2.
- Use
auto_routing: trueinstead 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.

