Most modern applications store information in databases, but users do not always know how to retrieve it. They may want to find orders, check customer activity, review product availability, or understand application usage without writing database queries.
For developers, supporting these requirements usually means creating multiple API endpoints, defining query parameters, implementing filters, and maintaining different query methods. As application data grows, the number of possible combinations also increases.
What if users could simply ask questions such as "Show me the five most popular products this month" or "Find customers who placed more than three orders last week"?
Google Cloud is bringing this capability to Firestore through Conversational Analytics. It allows developers to connect natural-language questions with operational database queries using Google's QueryData API.
The feature translates user questions into MongoDB-compatible Query Language (MQL), executes the generated queries, and returns results with explanations. Developers can use it to build conversational data experiences without manually creating an API endpoint for every possible analytical question.
In this article, we will explore how Conversational Analytics works with Firestore, configure the required Google Cloud environment, create a context set, generate MQL from natural-language questions, and integrate the capability into an application using MCP Toolbox and Python.
What Is Conversational Analytics in Firestore?
Conversational Analytics is a Google Cloud capability that allows users and applications to interact with database information through natural language.
Instead of requiring users to understand collection names, document structures, and query syntax, the system interprets their questions and generates database queries.
For example, consider an e-commerce application that stores customer orders in Firestore.
A traditional application might require a developer to create an API endpoint such as:
GET /api/orders?status=delivered&minAmount=1000
The user must understand the available filters and provide the correct parameters.
With Conversational Analytics, the user can ask:
"Show me delivered orders worth more than 1,000."
The system interprets the request, generates an appropriate database query, executes it, and returns the matching information.
Google announced Conversational Analytics support for Firestore and Bigtable on December 2, 2026. The Firestore integration is available in preview for Firestore Enterprise edition with MongoDB compatibility.
This distinction is important. The feature does not currently apply to every existing Firestore Native Mode database.
For Firestore, the generated query language is MongoDB-compatible Query Language (MQL).
Understanding QueryData
QueryData is the natural-language query capability available through the Conversational Analytics API.
It acts as the connection between a user's question and the database query engine.
When an application sends a natural-language question, QueryData performs several operations:
Understands the user's question and identifies the requested information.
Resolves business terms and values against the available database context.
Generates an MQL query.
Executes the generated query against the configured Firestore database.
Returns the query result, generated query, explanation, and optional natural-language answer.
For example, a user might ask:
"Find flights from San Francisco to New York."
QueryData can translate this request into an MQL query similar to the following:
db.flights.find({
departure_airport: "SFO",
arrival_airport: "JFK"
});
The application does not need to construct this query manually.
However, the quality of the generated query depends on the database schema, available context, and clarity of the user's question.
This is why QueryData supports context sets.
How Conversational Analytics Works
Understanding the architecture makes implementation easier.
The following diagram shows the general flow of a Firestore conversational application.
User
|
v
Natural Language
Question
|
v
Application Backend
|
v
Conversational Analytics
QueryData
|
v
Context Set and
Schema Metadata
|
v
MQL Query
|
v
Firestore Enterprise
MongoDB Compatibility
|
v
Query Results
|
v
Natural Language
Response
|
v
User
Each component has a specific responsibility.
The application receives the question and sends it to QueryData. QueryData uses the configured database context to understand the request and generate the appropriate query.
Firestore executes the query using the permissions of the configured database identity.
Finally, the application displays the returned information to the user.
This architecture separates natural-language interpretation from database execution.
Prerequisites for Implementing Conversational Analytics
Before starting the implementation, configure the Google Cloud environment.
The following requirements are needed:
Requirement | Purpose |
|---|
Google Cloud project | Hosts the database and related services |
Firestore Enterprise edition | Provides the supported database environment |
MongoDB compatibility | Enables MQL query generation |
Gemini Data Analytics API | Provides Conversational Analytics capabilities |
Gemini for Google Cloud API | Supports the required Google Cloud AI functionality |
Knowledge Catalog API | Supports context set management |
MCP Toolbox | Connects the application with QueryData |
Google Cloud CLI | Helps configure authentication and project access |
Enable the Required APIs
Enable the following services in your Google Cloud project:
Also ensure that the required Firestore database is created using Enterprise edition with MongoDB compatibility.
Configure IAM Permissions
The documented integration requires the following roles for the user performing the setup:
IAM Role | Purpose |
|---|
roles/datastore.viewer | Provides read access to Firestore data |
roles/serviceusage.serviceUsageConsumer | Allows consumption of enabled services |
roles/geminidataanalytics.queryDataUser | Allows use of QueryData |
For production deployments, assign permissions to the appropriate runtime identity rather than depending on an individual developer's credentials.
Creating a Sample Firestore Database
Let's consider a simple flight booking application.
The application stores flight information and airport details in two collections:
The flights collection contains departure information, arrival information, flight numbers, and departure times.
The airports collection contains airport codes, airport names, and city information.
We can create sample documents using MQL.
Creating the Airports Collection
Open Firestore Studio and execute the following MQL statement.
db.airports.insertMany([
{
iata: "SFO",
name: "San Francisco International Airport",
city: "San Francisco",
country: "United States"
},
{
iata: "JFK",
name: "John F. Kennedy International Airport",
city: "New York",
country: "United States"
},
{
iata: "LAX",
name: "Los Angeles International Airport",
city: "Los Angeles",
country: "United States"
},
{
iata: "BOS",
name: "Boston Logan International Airport",
city: "Boston",
country: "United States"
}
]);
This collection stores airport information that can be referenced by flight records.
Creating the Flights Collection
Next, create sample flight records.
db.flights.insertMany([
{
flight_number: "UA1532",
departure_airport: "SFO",
arrival_airport: "JFK",
departure_time: ISODate("2026-12-03T15:30:00Z"),
status: "scheduled",
price: 450
},
{
flight_number: "AA242",
departure_airport: "SFO",
arrival_airport: "JFK",
departure_time: ISODate("2026-12-03T18:30:00Z"),
status: "scheduled",
price: 520
},
{
flight_number: "DL1106",
departure_airport: "BOS",
arrival_airport: "LAX",
departure_time: ISODate("2026-12-03T20:00:00Z"),
status: "scheduled",
price: 390
}
]);
These records provide enough information to demonstrate natural-language filtering and querying.
The same database can be accessed through compatible MongoDB drivers and Firestore's supported native SDKs. However, the QueryData integration described here specifically targets the Enterprise edition MongoDB-compatible environment.
Understanding Context Sets
A context set is one of the most important parts of a production Conversational Analytics implementation.
A database schema tells the system how information is stored, but it does not always explain what the information means to the business.
Consider the following question:
"Find flights that avoid evening traffic."
The database may contain a departure_time field, but it does not know what the business means by evening traffic.
Does it mean between 5 PM and 7 PM? Does it include flights departing after 7 PM?
Without additional context, the system may interpret the request incorrectly.
Context sets help solve this problem by providing database-specific knowledge.
A context set supports three important components.
Query Templates
Query templates connect natural-language questions with validated MQL query patterns.
For example, the application might receive questions such as:
Find flights from a particular city.
Show flights between two airports.
Find flights that avoid evening traffic.
Instead of generating every query from scratch, QueryData can match the question against an existing template and replace its parameters.
This improves consistency for frequently used business questions.
Query Facets
Query facets are reusable filtering conditions that can be combined with query templates.
For example, a flight-search template may support additional conditions such as:
Flight status
Departure date
Maximum ticket price
Arrival airport
These filters can be combined dynamically without creating a separate template for every possible combination.
Value Searches
Value searches help resolve business terms and values against actual database records.
For example, a user may enter:
"Find flights departing from San Fran."
The database stores the city as San Francisco.
Value search helps connect the informal expression with the actual database value.
It can also help resolve synonyms, spelling variations, and ambiguous terms.
Together, these three components help QueryData generate queries that better reflect the application's business requirements.
Creating a Context Set for Firestore
After creating the database and collections, the next step is to create a context set.
Google Cloud provides Firestore Studio and the Context Engineering Agent to help developers create and manage context.
The process involves the following steps:
Open the Google Cloud Console and navigate to Firestore.
Select your Firestore Enterprise database with MongoDB compatibility.
Open Firestore Studio.
Navigate to Context sets.
Create a new context set.
Provide a meaningful name, such as flights-assistant.
Configure the database context.
Generate or upload the context set configuration.
Save the context set.
For more advanced applications, the Context Engineering Agent can help generate query templates, facets, and value searches based on the database schema and representative questions.
Adding a Query Template
Suppose we want to support the following question:
"Find flights from San Francisco to New York."
The corresponding MQL query is:
db.flights.find({
departure_airport: "SFO",
arrival_airport: "JFK"
});
A parameterized version can replace the airport values with placeholders.
db.flights.find({
departure_airport: $1,
arrival_airport: $2
});
The context set can associate the natural-language question with the parameterized query.
This allows QueryData to recognize similar questions with different airport codes.
For example:
"Show me flights from Boston to Los Angeles."
The system can reuse the same query structure with different values.
A context set is not simply a collection of prompts. It provides reusable database knowledge that helps the query engine interpret different ways of asking the same business question.
Testing Natural Language Queries in Firestore Studio
Before connecting QueryData to an application, test it inside Firestore Studio.
Open the context set created earlier and select the option to test it.
Enter the following question:
Find flights from SFO to JFK.
QueryData should generate an MQL query similar to:
db.flights.find({
departure_airport: "SFO",
arrival_airport: "JFK"
});
Review the generated query before proceeding.
Now try a more descriptive question:
Show me flights from San Francisco to New York.
The system should use the available airport context to resolve the city names to the appropriate airport codes.
This is where value searches become useful.
You can also test questions that use business terminology.
For example:
Find flights that help me avoid evening traffic
when traveling from San Francisco.
If the context set defines evening traffic as a specific time range, QueryData can use that definition while generating the MQL query.
The exact generated query depends on the configured context and available database information.
Integrating QueryData Into an Application Using MCP Toolbox
Testing queries in Firestore Studio is useful during development, but most applications need an integration that can be called from application code.
Google's documented integration uses MCP Toolbox to expose the Gemini Data Analytics QueryData functionality as a tool.
MCP Toolbox acts as an integration layer between the application and the Conversational Analytics API.
The application sends a question to the tool, which forwards it to QueryData and returns the generated MQL, results, and explanations.
Installing MCP Toolbox
Download MCP Toolbox version 1.14.0 or later.
Configure Google Cloud Application Default Credentials.
Run the following commands:
gcloud auth application-default login
gcloud auth application-default set-quota-project PROJECT_ID
Replace PROJECT_ID with your Google Cloud project ID.
Application Default Credentials allow local development tools to authenticate using the configured Google Cloud identity.
For production deployments, use an appropriately configured service account or workload identity instead of relying on a developer's local credentials.
Configuring the QueryData Tool
Create a tools.yaml configuration file.
Add the following configuration:
kind: source
name: gda-api-source
type: cloud-gemini-data-analytics
projectId: "PROJECT_ID"
---
kind: tool
name: cloud_gda_query_tool
type: cloud-gemini-data-analytics-query
source: gda-api-source
description: >
Send natural language questions to Firestore
and receive MQL queries, results, and explanations.
location: "REGION_ID"
context:
datasourceReferences:
firestoreReference:
databaseReference:
projectId: "PROJECT_ID"
databaseId: "DATABASE_ID"
agentContextReference:
contextSetId: "CONTEXT_SET_ID"
generationOptions:
generateQueryResult: true
generateNaturalLanguageAnswer: true
generateExplanation: true
generateDisambiguationQuestion: true
Replace the configuration values:
Placeholder | Description |
|---|
PROJECT_ID | Google Cloud project ID |
REGION_ID | Region configured for the QueryData integration |
DATABASE_ID | Firestore database ID |
CONTEXT_SET_ID | ID of the context set created earlier |
One important detail is that the context set region must match the region where the context set was created. It can differ from the Firestore database region.
The generation options control the information returned by QueryData.
generateQueryResult requests the database query result.
generateNaturalLanguageAnswer requests a readable answer.
generateExplanation requests an explanation of the generated query.
generateDisambiguationQuestion allows the system to request clarification when a question is unclear.
For production applications, keep runtime tool configurations separate from development tools that inspect schemas or execute administrative operations.
Starting MCP Toolbox
After configuring tools.yaml, start the Toolbox server.
./toolbox --config ./tools.yaml
The server exposes the configured QueryData tool to connected applications.
Keep the server running while testing the application.
For production environments, deploy the Toolbox server using an appropriate managed infrastructure and secure its network access.
Building a Python Application That Uses QueryData
Now we can create a small application that connects to the QueryData tool.
Google's documented integration uses the Google Agent Development Kit (ADK) and the MCP Toolbox Python SDK.
Create a new project.
mkdir firestore-conversational-app
cd firestore-conversational-app
uv init
uv add google-adk toolbox-core google-genai
Create an ADK agent:
uv run adk create my_agent
Configure the agent using a supported Gemini model and your selected authentication method.
Next, update the agent.py file.
from typing import cast
from google.adk.agents.llm_agent import Agent
from google.adk.agents.llm_agent import ToolUnion
from toolbox_core import ToolboxSyncClient
TOOLBOX_URL = "http://127.0.0.1:5000"
INSTRUCTION = """
You are a Firestore data assistant.
Help users retrieve information from the
Firestore database using natural language.
Use the QueryData tool for database questions.
Always inspect the generated query and
intent explanation before presenting results.
If the query requires clarification,
ask the user for additional information.
Do not invent database records or values.
Do not claim that a filter was applied
unless it is present in the generated query.
If the tool returns an error, explain that
the requested information could not be retrieved.
"""
client = ToolboxSyncClient(TOOLBOX_URL)
query_tool = client.load_tool(
"cloud_gda_query_tool"
)
root_agent = Agent(
model="gemini-3.5-flash",
name="firestore_assistant",
instruction=INSTRUCTION,
tools=cast(list[ToolUnion], [query_tool]),
)
This example follows the documented ADK and Toolbox integration pattern.
The Toolbox client connects to the running server and loads the QueryData tool.
The ADK agent uses that tool whenever the user asks a question that requires Firestore information.
The agent's instructions also explain how to handle unclear questions and avoid presenting unsupported results.
The outer agent and QueryData have different responsibilities. The outer agent manages the conversation, while QueryData handles the database-specific natural-language query operation.
The configured Gemini model is used by the outer ADK agent. QueryData itself provides the database query generation and execution capability.
Running the Application
Start the ADK web interface:
uv run adk web --port 8000
Open the local application and ask:
Find flights from San Francisco to New York.
The agent can call the QueryData tool, retrieve the matching flight information, and present the result in a readable format.
You can also try:
Show me flights departing from Boston.
Or:
Which flights have the highest ticket prices?
The actual response depends on the records available in your Firestore database.
Handling Ambiguous Natural Language Questions
One important advantage of Conversational Analytics is its ability to identify questions that do not contain enough information.
Consider this question:
"Show me flights departing from the west side."
The database may contain airport names and city information, but it may not define which airports belong to the west side.
A basic LLM integration might guess a city or airport and generate a query.
QueryData can instead return a disambiguation question explaining that the database does not contain enough information to identify the requested airports.
The application can then ask the user to provide a specific city or airport.
For example:
I could not determine which airports you mean
by the west side.
Would you like to search for flights departing
from San Francisco, Los Angeles, or another city?
This is better than returning a confident but incorrect result.
Applications should treat disambiguation responses as a normal part of conversational interaction rather than as system errors.
Understanding QueryData Responses
When integrating QueryData, developers should pay attention to the different fields returned by the tool.
Response Field | Purpose |
|---|
generated_query | Contains the generated MQL query |
query_result | Contains the database query results |
intent_explanation | Explains how the question was interpreted |
natural_language_answer | Provides a readable summary |
disambiguation_question | Requests clarification when required |
These fields are useful for building a transparent application.
For example, an application can display the natural-language answer to ordinary users while recording the generated query and explanation for debugging and auditing.
The generated query should not be hidden from developers during testing. Reviewing it helps identify incorrect field mappings, missing filters, and unexpected query behavior.
Security Considerations for Firestore Applications
Natural-language database access introduces security concerns that developers must understand before using this functionality in production.
A conversational interface can make database access easier, but it must not become a way to bypass existing application permissions.
Understand the Preview Access Limitations
The current preview integration for Firestore with MongoDB compatibility does not support fine-grained access controls at the collection, document, or field level.
The QueryData runtime identity can read the entire database within its granted access.
This means that Firebase Security Rules do not automatically restrict the queries executed through QueryData.
For example, suppose an application has two customer accounts:
A traditional Firebase application may restrict each customer to their own documents through Security Rules.
However, the QueryData integration described here does not automatically apply those application-user restrictions to generated database queries.
Developers must not assume that a logged-in application user can safely access QueryData results using the same authorization model as the normal Firebase client SDK.
Use Least-Privilege IAM Permissions
The runtime identity should have only the database permissions required for the application.
For read-only conversational analytics, use the documented viewer permission and avoid granting unnecessary write or administrative access.
Validate Generated Queries and Explanations
Always inspect the generated query and its explanation during development and evaluation.
Check whether:
The correct collection is queried.
The expected filters are applied.
Date conditions are interpreted correctly.
The requested limits are respected.
The result contains only the expected information.
A syntactically valid query is not necessarily a semantically correct query.
Protect Sensitive Information
Do not expose confidential records through a conversational interface simply because the database identity has access to them.
Until fine-grained authorization is available for this integration, avoid using it for customer-facing multi-tenant queries that require strict per-user document or field isolation.
For those scenarios, keep data access behind application-controlled APIs that enforce authorization before returning results.
Conversational Analytics vs. Traditional Firestore Queries
Both approaches are useful, but they serve different application requirements.
Feature | Traditional Firestore Queries | Conversational Analytics |
|---|
Query input | Structured application parameters | Natural-language questions |
Query construction | Developer writes query logic | QueryData generates MQL |
Flexibility | Defined by implemented endpoints | Supports different question phrasing |
Business terminology | Must be handled by application logic | Can be defined through context sets |
Query explanation | Developer implements it | Generated intent explanation |
Ambiguity handling | Application-specific | Supports disambiguation questions |
Access control | Firebase Security Rules or server-side authorization, depending on access method | Database IAM permissions in the current preview integration |
Best use case | Standard application operations | Conversational data exploration |
Traditional queries remain important for operations such as creating orders, updating customer profiles, and processing payments.
Conversational Analytics is better suited to read-oriented questions that involve filtering, searching, and analyzing existing information.
It should complement normal database access rather than replace the application's complete data-access layer.
Advantages of Using Conversational Analytics
Natural Language Interface
Users can retrieve information without understanding database collection names or MQL syntax.
This makes analytical features easier to use for business teams and nontechnical users.
Less Manual Query Development
Developers do not need to create a separate endpoint for every possible combination of filters.
QueryData can generate queries based on user questions and the available database context.
Better Understanding of Business Terms
Context sets allow developers to define business terminology, reusable query patterns, and value mappings.
This helps the system understand the language used within a particular organization.
Query Explanations
Generated queries and explanations provide useful information for developers and administrators.
They help identify how a question was interpreted and which database conditions were applied.
Application and Agent Integration
MCP Toolbox allows applications and agent frameworks to connect with QueryData through a reusable tool interface.
This makes it easier to integrate conversational database access into larger AI workflows.
Disadvantages and Limitations
Preview Availability
The Firestore integration is currently a preview feature and is subject to Google's pre-GA terms.
Its availability and behavior may change.
Database Edition Requirement
The integration requires Firestore Enterprise edition with MongoDB compatibility.
Applications using only the standard Firestore Native Mode database cannot directly assume support for this feature.
Limited Fine-Grained Access Control
The current preview does not support collection-level, document-level, or field-level access restrictions through QueryData.
This is a major consideration for applications that store sensitive or tenant-specific information.
Generated Queries Require Validation
Natural-language processing is not perfect.
Incorrect interpretations, ambiguous questions, and missing business context can produce unexpected query results.
Additional Infrastructure
An application may need MCP Toolbox, context sets, Google Cloud APIs, IAM configuration, and an outer agent framework.
This adds operational complexity compared with a simple Firestore query.
Best Practices for Production Applications
Start With Common Business Questions
Identify the questions users frequently ask before creating context sets.
For an e-commerce application, these might include:
Which products received the most orders?
Which orders are still pending?
Which customers made purchases this month?
Which products are running low on stock?
Build and validate query templates for these common scenarios.
Maintain Accurate Schema Descriptions
Collection and field descriptions should explain their business meaning.
For example, a field named order_status is not sufficiently descriptive by itself.
Explain the possible values and what each value represents.
This helps QueryData understand the relationship between user terminology and stored information.
Build a Golden Query Test Set
Maintain a collection of representative natural-language questions and their expected MQL queries or results.
Use these tests to evaluate changes to the context set.
Include different wording variations, filters, date ranges, and ambiguous questions.
Improve Context Gradually
Do not attempt to create every possible query template before launching the application.
Start with the most important questions, evaluate the results, identify incorrect interpretations, and add the required context.
This iterative approach makes context management more practical.
Separate Development and Runtime Tools
Use separate MCP Toolbox configurations for development and production.
Development tools may require schema inspection and query validation, while runtime applications should expose only the tools they need.
Monitor Query Results
Record query execution status, generated query information, response times, and failure details.
Avoid storing unnecessary customer information in application logs.
Keep Sensitive Operations Outside Conversational Queries
Use standard, application-controlled APIs for write operations such as creating orders, updating profiles, deleting records, and processing payments.
Keep conversational analytics focused on approved read operations.
Common Mistakes to Avoid
Assuming It Works With Every Firestore Database
The current integration targets Firestore Enterprise edition with MongoDB compatibility.
It should not be confused with Gemini assistance for generating MQL in Firestore Studio or with the traditional Firestore Native Mode SDK.
Skipping Context Set Configuration
Raw database schemas may not explain business-specific terminology.
Without useful context, a question such as "Find high-value customers" may be interpreted incorrectly.
Define the business rules through query templates, facets, and value searches.
Trusting Generated Queries Without Inspection
A query can execute successfully and still return the wrong information.
Review the generated query and intent explanation, especially for business-critical requests.
Relying on Firebase Security Rules
The current QueryData integration does not automatically enforce Firebase Security Rules.
Do not use it as a replacement for application-level authorization in multi-tenant applications.
Exposing Development Tools in Production
Schema inspection and administrative tools should not be unnecessarily available to runtime applications.
Use a dedicated production Toolbox configuration with a restricted tool set.
Troubleshooting Common Issues
Problem | Possible Cause | Recommended Solution |
|---|
QueryData API access denied | Missing IAM permissions | Verify the required Google Cloud roles |
Firestore database is not supported | Incorrect database edition or compatibility mode | Use Enterprise edition with MongoDB compatibility |
MCP Toolbox cannot connect | Incorrect server address or configuration | Verify the Toolbox process and tools.yaml |
Context set cannot be found | Incorrect context set ID or region | Verify the full context set reference |
Generated MQL is incorrect | Missing business context | Add query templates, facets, or value searches |
Application returns ambiguous results | Question does not provide enough information | Request clarification from the user |
Query returns unexpected documents | Generated filters do not match the intended business rules | Inspect generated_query and intent_explanation |
Permission behavior differs from Firebase SDK | QueryData uses database IAM permissions | Review the runtime identity and database access model |
During development, use Firestore Studio to test individual questions before investigating application-level integration problems.
Summary
Conversational Analytics brings natural-language database querying to Firestore through Google's QueryData API.
Instead of requiring users to understand MongoDB-compatible query syntax, applications can accept ordinary questions and translate them into executable MQL queries.
In this article, we explored how QueryData works, created sample Firestore collections, discussed context sets, configured the required Google Cloud services, and integrated the QueryData tool into a Python application using MCP Toolbox and Google ADK.
We also examined important production considerations, including IAM permissions, query validation, context management, and the limitations of the current preview access model.
The most important part of this implementation is not simply converting natural language into MQL. It is providing enough database and business context to generate useful queries while maintaining strict security boundaries.
For applications that need conversational access to operational data, Conversational Analytics offers an interesting approach. However, developers should evaluate its current preview limitations carefully before using it with sensitive customer information or multi-tenant application data.
Join the conversation! Your thoughts help the community grow.