In the last post I asked whether the AI writing your Cypress tests actually knows your app. This one gets into what it looks like to give it that knowledge, with a real example I built locally.
The pattern is RAG, Retrieval-Augmented Generation. At its core it is straightforward. You index your app's documents into a vector database, and at query time, the most relevant chunks are retrieved and passed to the AI as context. The AI generates a response grounded in your actual docs rather than guessing.
What I Indexed for Sauce Demo
I used Sauce Demo as my test app and created three docs:
- An API spec covering login, inventory, cart, and checkout endpoints
- A component doc with exact CSS selectors for every page
- A bug history doc covering known failure scenarios like locked out users, problem user add to cart issues, and checkout validation gaps
Not everything needs to be indexed. What actually moved the needle was the component selectors and the bug history. The AI stopped guessing at button labels and started working from real data.
The Pipeline
I used ChromaDB as the vector database and Google Gemini embeddings to index the docs. The script follows five simple steps:
// Load environment variables
// Set up Google Gemini embeddings
// Connect to ChromaDB
// Read and chunk your docs
// Embed and store each chunk
Querying the Index
Once indexed, when you need a test step, you query the index, pull the most relevant chunks, and feed them to the AI before cy.prompt() ever runs. It is a wrapper, not a native feature.
Here is what came back when I queried "user login with valid credentials":
Chunk 1: Login API spec with username and password structure
Chunk 2: Exact CSS selectors for the login page
Chunk 3: Known bug history related to login and locked out user
The AI now had everything it needed. The right selectors. The right endpoints. The known failure scenarios. All retrieved automatically from the docs.
A couple of things worth knowing before you try this:
- ChromaDB needs to run as a separate service before you index or query anything
- The embedding model name matters. For Google Gemini the correct model is gemini-embedding-001
- RAG is a pre-processing layer, not a direct injection into cy.prompt(). You need a wrapper to bridge the two
Still figuring out the best chunking strategy for API specs. If you have tackled this before I would love to know what worked for you.

Top comments (0)