Search Tutorial
Introduction
This tutorial covers the GroundX search API.
If you’d rather have an agent search and answer for you instead of wiring this up in application code, see Ingest, Search, and Answer With an Agent.
Under the hood, the GroundX Search API does the following:
-
Analyzes your search query and improves it if necessary, then runs a semantic search that avoids the hallucination trap most RAG apps fall into with vectorized search.
-
Searches the GroundX buckets where your content and its extra search data are stored. GroundX’s extra search data keeps your content in its original context. The Search API returns more than raw text chunks: a response bundled with intelligible text chunks, extra search data, automatically generated document and section summaries, source URL, and a readable, contextualized, performant version of the text chunk ready for LLM use.
-
Uses a proprietary re-ranker that scores every chunk on how well it answers the original question, so the most trustworthy results are on top.
-
Merges all of this into a simple text block you can send to the LLM of your choice, for accurate, contextualized, hallucination-free responses from your content.
LLM Integration
GroundX handles the heavy lifting in the background. Here’s the flow:
- Make an API search request.
Example:
API Key
- Go to the GroundX dashboard to get your API key.
- GroundX can be installed for Python via pip install groundx
- GroundX can be installed for NPM via npm i -s groundx
- Retrieve the
search.textproperty and pass it on to the LLM of your choice.
Example:
LLM API
Make sure to get the API key, endpoints, and SDK from your LLM provider. For example, if using ChatGPT, go to the OpenAI documentation
- Get a response from the LLM using your retrieved data.
Example using:
The end result: retrievals that outperform traditional vector systems and boost the accuracy of LLM completions.
Getting Started
The example above used placeholder values. Here’s the same flow with more detail on each parameter.
To make an API request, do the following:
Ingest content
Make sure you’ve already uploaded the content you want to search to a GroundX bucket. See the documentation on content ingestion for more information.
Set up environment
Set up your environment with the GroundX SDK.
Bucket or Group ID
Get the ID of the group or bucket you want to search.
Example:
See the documentation on content ingestion for more information to learn about bucket creation.
Search Query String
Create a search query string — a question or the keywords you want to search for.
If the string is more than 30 words long, GroundX automatically rewrites it with keywords using its internal LLM.
GroundX processes the string against your content and its extra search data to retrieve the most relevant results.
Example:
Number of Results
Optionally, set the number of results returned by the search request. By default, search queries return up to 20 results.
Example:
API Request
Make the API search request, including the ID and search query string in the request body.
In addition to id, query, and n, the search request accepts a few more optional
parameters:
For search rate limits (concurrent requests, requests per minute) and error-handling guidance, see the Direct SDK/API Quickstart’s Errors and Rate Limits section.
Example:
API Response
The request returns a Search object.
The Search schema includes the following details.
Response sample:
Recommended data
The most significant property in the search response is text: a string containing the
automatically rewritten text chunks and the extra search data added to the original
content. This content, generated by GroundX’s internal LLM, is intelligible,
contextualized, and machine-understandable — pass it straight to your LLM.
Advanced data handling
We recommend passing search.text directly to your LLM, but you can also add your own
logic around the search.results property.
results is a list of the original text chunks that matched the search query, ordered by
a score based on semantic search and re-ranking. Each result includes the suggested text
mentioned above — the more intelligible, performant version of the text chunk.
Each result also carries automatically generated extra search data, like summaries of the
document and section the chunk is found in. As of SDK 3.5.4, the document-level and
section-level summaries are also available directly on each result as the top-level
fileSummary and sectionSummary fields, in addition to the documentSummary/
sectionSummary pair inside searchData — use the top-level fields when you just need
the summary text and don’t need the rest of searchData.
The GroundX URL, document ID, and bucket ID of the source content are provided too.
Each result also carries a unique chunkId, and — when the chunk is a visual element such
as a table or chart — a multimodalUrl pointing to an image clipping of that element. For
source-attribution UIs, boundingBoxes gives the coordinates of where the chunk appears
on its source page(s), and pages gives the rendered page image(s) (with pixel
dimensions) those coordinates are relative to.
Use verbosity (see API Request above) to control whether results is returned at all,
and whether each result includes the full searchData object.
Final Details
You’re now ready to integrate GroundX with your LLM to generate accurate, hallucination-free responses from your own content.
Next Steps
- For tips on turning search results into consistent, high-quality LLM responses, see Prompting and Integration.
- Want an agent to run search and answer for you instead of wiring this up in application code? See Ingest, Search, and Answer With an Agent (also linked in the Introduction above).

