What-If Story Generator: Building a Narrative Assistant with RAG

From 'What If?' to Outline: My Gen AI Capstone Project Using RAG Have you ever had a cool "What if...?" idea pop into your head, maybe for a story, game, or just for fun? It happens to me all the time! But sometimes, taking that initial spark and turning it into a structured plot or concept can be tricky. That's exactly the challenge I wanted to tackle for my final project in Google's recent Gen AI Intensive Course. About the Course and Capstone The Gen AI Intensive Course was a fantastic 5-day dive (held March 31 - April 4, 2025) into the latest advancements in Generative AI, hosted by Google. The final part was the Capstone Project (due April 20, 2025), where we participants got to apply the cool techniques we learned – things like understanding text and images, using AI agents, and more – to a creative project of our own choosing. We needed to showcase at least three specific Gen AI capabilities. The goal? To build something innovative and demonstrate our newfound skills! My Project: The What-If Story Generator For my capstone, I created the "What-If Story Generator." My goal was simple: build a tool that takes any user's "What if...?" question and automatically generates a well-structured, creative story outline in Markdown format. Think of it as an AI assistant to help kickstart the storytelling process. The Challenge: Bridging Imagination and Structure Coming up with "What if?" ideas is often the easy part. The hard part is developing that idea: Who are the characters? What happens first? What's the climax? My generator aims to help with that "middle step" by providing a starting framework. How It Works: The Magic of RAG The core technology behind the generator is something called Retrieval-Augmented Generation (RAG). What's RAG? In simple terms, it means the AI doesn't just generate text from scratch. First, it retrieves (looks up) relevant information related to the prompt, and then it uses that information to generate a more informed and coherent response. It's like doing a quick research check before answering a question! My system uses a two-stage RAG approach: Stage 1: Finding Relevant Information (Retrieval) Checking Inside: It first searches a small, internal database (ChromaDB) filled with fantasy/sci-fi concepts using Embeddings (AI that understands word meanings) to find related ideas. Checking Outside (If Needed): If the internal database doesn't have enough relevant info (based on a similarity score), the system smartly uses Google Grounding. It asks the powerful Gemini 1.5 Pro model to do a focused search for external facts or concepts related to the "What if?" prompt. This keeps the story elements logical and consistent. Stage 2: Creating the Story Outline (Generation) Once it has gathered the best information (either internal or external), Gemini 1.5 Pro steps in again. It takes the user's original "What if?" idea and the retrieved context and weaves them together into a narrative outline. The output is neatly formatted in Markdown with helpful sections like Premise, Characters, Turning Points, Resolution, and a Takeaway Theme. Demonstrating Gen AI Skills The Capstone required using at least three Gen AI capabilities learned in the course. My project utilizes several, including: Embeddings: To understand the meaning of the user's prompt for smart information retrieval. Vector Search/Store (ChromaDB): To efficiently store and search the internal knowledge base based on semantic similarity. Grounding: To fetch external context using Gemini when internal knowledge is insufficient, making the story more robust. Retrieval-Augmented Generation (RAG): The entire system is built around this principle, using retrieved information to guide the AI's creative generation. Helpful Features Included I also added some practical touches: Quota-Smart Generation: It automatically retries if there's a temporary API glitch, making it more reliable. Caching: Saves results for repeated prompts to speed things up and save resources. Markdown Output: Ensures the outline is clean and easy to read/use. Auto-Evaluation: Performs a basic check to ensure the generated outline has all the sections and isn't too long. Example Output Here's a snippet of what the generator might produce for "What if gravity reversed every midnight for one minute?": ## Premise What if gravity reversed every midnight for one minute, a city's clock tower was the heart of a slumbering titan, and the moon whispered secrets? ## Characters - **Protagonist**: Elara, a clockwork mechanic attuned to the city's rhythms... - **Antagonist / Force**: The Titan, its stone slumber beneath the city disturbed by the hourly chimes... ## Turning Points 1. **Inciting Incident**: The first reversed-gravity minute was chaos... Elara noticed the clock tower’s glow intensified... 2. **Rising Conflict**: Each night, the minute of inverted gravity grew more violent... Elara discovered the connectio

Apr 21, 2025 - 11:43
 0
What-If Story Generator: Building a Narrative Assistant with RAG

From 'What If?' to Outline: My Gen AI Capstone Project Using RAG

Have you ever had a cool "What if...?" idea pop into your head, maybe for a story, game, or just for fun? It happens to me all the time! But sometimes, taking that initial spark and turning it into a structured plot or concept can be tricky. That's exactly the challenge I wanted to tackle for my final project in Google's recent Gen AI Intensive Course.

About the Course and Capstone

The Gen AI Intensive Course was a fantastic 5-day dive (held March 31 - April 4, 2025) into the latest advancements in Generative AI, hosted by Google. The final part was the Capstone Project (due April 20, 2025), where we participants got to apply the cool techniques we learned – things like understanding text and images, using AI agents, and more – to a creative project of our own choosing. We needed to showcase at least three specific Gen AI capabilities. The goal? To build something innovative and demonstrate our newfound skills!

My Project: The What-If Story Generator

For my capstone, I created the "What-If Story Generator." My goal was simple: build a tool that takes any user's "What if...?" question and automatically generates a well-structured, creative story outline in Markdown format. Think of it as an AI assistant to help kickstart the storytelling process.

The Challenge: Bridging Imagination and Structure

Coming up with "What if?" ideas is often the easy part. The hard part is developing that idea: Who are the characters? What happens first? What's the climax? My generator aims to help with that "middle step" by providing a starting framework.

How It Works: The Magic of RAG

The core technology behind the generator is something called Retrieval-Augmented Generation (RAG).

What's RAG? In simple terms, it means the AI doesn't just generate text from scratch. First, it retrieves (looks up) relevant information related to the prompt, and then it uses that information to generate a more informed and coherent response. It's like doing a quick research check before answering a question!

My system uses a two-stage RAG approach:

  1. Stage 1: Finding Relevant Information (Retrieval)

    • Checking Inside: It first searches a small, internal database (ChromaDB) filled with fantasy/sci-fi concepts using Embeddings (AI that understands word meanings) to find related ideas.
    • Checking Outside (If Needed): If the internal database doesn't have enough relevant info (based on a similarity score), the system smartly uses Google Grounding. It asks the powerful Gemini 1.5 Pro model to do a focused search for external facts or concepts related to the "What if?" prompt. This keeps the story elements logical and consistent.
  2. Stage 2: Creating the Story Outline (Generation)

    • Once it has gathered the best information (either internal or external), Gemini 1.5 Pro steps in again.
    • It takes the user's original "What if?" idea and the retrieved context and weaves them together into a narrative outline.
    • The output is neatly formatted in Markdown with helpful sections like Premise, Characters, Turning Points, Resolution, and a Takeaway Theme.

Demonstrating Gen AI Skills

The Capstone required using at least three Gen AI capabilities learned in the course. My project utilizes several, including:

  • Embeddings: To understand the meaning of the user's prompt for smart information retrieval.
  • Vector Search/Store (ChromaDB): To efficiently store and search the internal knowledge base based on semantic similarity.
  • Grounding: To fetch external context using Gemini when internal knowledge is insufficient, making the story more robust.
  • Retrieval-Augmented Generation (RAG): The entire system is built around this principle, using retrieved information to guide the AI's creative generation.

Helpful Features Included

I also added some practical touches:

  • Quota-Smart Generation: It automatically retries if there's a temporary API glitch, making it more reliable.
  • Caching: Saves results for repeated prompts to speed things up and save resources.
  • Markdown Output: Ensures the outline is clean and easy to read/use.
  • Auto-Evaluation: Performs a basic check to ensure the generated outline has all the sections and isn't too long.

Example Output

Here's a snippet of what the generator might produce for "What if gravity reversed every midnight for one minute?":

## Premise
What if gravity reversed every midnight for one minute, a city's clock tower was the heart of a slumbering titan, and the moon whispered secrets?

## Characters
- **Protagonist**: Elara, a clockwork mechanic attuned to the city's rhythms...
- **Antagonist / Force**: The Titan, its stone slumber beneath the city disturbed by the hourly chimes...

## Turning Points
1. **Inciting Incident**: The first reversed-gravity minute was chaos... Elara noticed the clock tower’s glow intensified...
2. **Rising Conflict**: Each night, the minute of inverted gravity grew more violent... Elara discovered the connection between the clock tower, the reversed gravity, and the Titan’s awakening...
3. **Climax**: Elara climbed the clock tower, fighting the upward pull... She reached the clock’s heart... The moon's whispers promised power...

## Resolution
The clock tower pulsed... Elara... made her choice... The red moon watched, whispering secrets only it now knew.

## Takeaway
*Sometimes, the greatest power lies in silencing the whispers that promise more.*

Learnings and Future Ideas

Building this project was an amazing way to solidify my understanding of RAG, grounding, and working with powerful models like Gemini 1.5 Pro. It was fascinating to see how AI can be a partner in the creative process.

Of course, there's always more to do! The internal knowledge base is small right now. Future ideas include building a proper web UI (maybe with Streamlit!) and even adding optional AI image generation to visualize scenes.

Conclusion

The What-If Story Generator was my way of exploring how Gen AI can help turn imaginative sparks into tangible starting points for stories. Participating in the Google Gen AI Intensive Course and completing this Capstone Project was a rewarding experience, pushing me to apply cutting-edge AI techniques to a fun, creative problem. I'm excited to see how these tools continue to evolve and empower human creativity!