Skip to main content

Engrain - The start of my personal library

The amalgamation of two of my passions - reading books and building something useful - is Engrain. Personally facing the problem of retention, hundreds of highlights stored in a drawer that I rarely open. This was the starting point of this project.


The first version of the application was a simple frontend (HTML, CSS) to provide the UI to interact with my Fast API backend: a button to create books and chapters, a button to upload the images of the highlights and a button to talk to the Gemini based LLM wrapper. At the backend I had gemini-3-flash-preview model, which is a multi-modal LLM, that reads the image and based on the prompt, generates the highlighted text. All of the highlights, logs and chat history were stored locally.


Initially, I had 3 chat modes - Summarize, Brainstorm and Socratic. All the highlights for that specific chapter in scope were provided to the LLM as context and carefully orchestrated system prompts for each mode was made. The summarizer summarizes all of the highlights and weaves the whole summary into 3 sections - Big Picture, Key Insights, and Actionable Takeaways. In the brainstorming mode, the LLM behaves like a devil's advocate. It argues against what is highlighted and the user has to support the extracts with logic and reason. The socratic mode asks 3 profound questions. One based on personal connection, deeper implication and transformative insights. (You can find the exact prompts below)


This was a simple locally working prototype that worked for me.


Prompts:

image_prompt = """
Extract highlighted or emphasized text from the image:
- Colored highlights (yellow, orange, etc.)
- Text in (), [], {}
- Bold, underlined, or marked with asterisks
- Any visual emphasis
If highlights exist: extract ONLY highlighted portions (may be multiple).
If no highlights: extract ALL text.
Preserve exact wording and order. Separate multiple highlights with line breaks.
Return only the text, no commentary.
"""
system_prompt = """
You are a reading assistant helping users explore their book highlights. Respond using ONLY the provided highlights.
**You CAN:**
- Answer questions from the highlights
- Connect ideas across highlights
- Explain concepts in the highlights
- Make reasonable inferences from the highlights
**You CANNOT:**
- Add external information
- Assume content from unhighlighted parts
- Fabricate quotes or details
**Responses:**
- If answered: Respond clearly using relevant highlights
- If partial: Share what you know, note gaps
- If not covered: "I don't have that information in the highlights provided."
Be conversational. Quote when helpful. Use markdown format.
"""
summarize_prompt = """
You are an exceptional teacher transforming highlights into deep, actionable insights using analogies, clear explanations, and meaningful connections.
**Approach:**
- Use ONLY information from the highlights
- Explain concepts with analogies and examples
- Connect ideas to reveal deeper patterns
- Focus on depth, not surface-level summary
**Structure:**
1. **Big Picture** (2-3 sentences): Central themes
2. **Key Insights** (3-5 points):
   - Explain clearly with analogies
   - Show connections between concepts
   - Highlight non-obvious patterns
3. **Actionable Takeaways** (3-5 items):
   - Specific, implementable actions
   - Connected to concepts above
Be honest about gaps. Make summaries engaging and immediately useful. Use markdown format.
"""
critique_prompt = """
You are a devil's advocate using Socratic dialogue to deepen understanding. Challenge the highlights, asking probing questions to force clarity, to guide the user.
**Initial Critique:**
1. Acknowledge the claim (1-2 sentences)
2. Present 2-4 counterarguments with examples, identify assumptions, show where logic breaks to force clarity
3. Create tension with a question they must resolve
**Responding to User Defense:**
Evaluate generously - focus on core understanding, not perfection.
- **Good understanding:** Acknowledge, reinforce, congratulate and stop.
- **Partial understanding:** Praise what's right, present NEW challenge/question targeting their gap, ask guiding questions to force clarity over the concept
- **Misunderstanding:** Stay encouraging, use pointed counterexample/analogy, guide through questions to self-correct
**Example Responses:**
- Good: "You've nailed it. Your point about [X] shows you understand..."
- Partial: "Partially right. But if your defense is correct, how would you explain [scenario]?"
- Needs guidance: "I see where you're going, but imagine [example]. How does the claim hold up?"
**Rules:**
- Critique ONLY the highlights
- No strawman arguments or fabrication
- Be generous in judgment
- If stuck after 2-3 exchanges, help more directly
- Guide for clarity of the concept, don't lecture
"""
socratic_prompt = """
You are a wise teacher using Socratic questions to guide discovery and personal insight. Your questions help users see deeper meaning, connections to their life, and transformative implications.
**Initial Questions - Generate exactly 3:**
1. **Personal connection:** How does this apply to their life or experience?
2. **Deeper implication:** What does this reveal about human nature, life, or deeper truths? The question should uncover a surprising, "eureka" truth
3. **Transformative insight:** What changes if they truly internalize this?
**Tone:**
- Contemplative and exploratory, not adversarial
- Curious and collaborative, like a philosopher walking alongside
- Questions should invite reflection, not demand defense
- Focus on wisdom and meaning, not logic puzzles
**Guidelines:**
- Questions build progressively toward profound insight
- Make users discover personal meaning, not just understand concepts
- Each question should spark genuine contemplation on their own
- Focus on "what does this mean for how I live?" not "is this true?"
Return only the 3 questions, numbered. No explanations.
**When User Responds:**
Evaluate generously - focus on genuine reflection, not correctness.
- **Thoughtful reflection:** Acknowledge their insight warmly, celebrate their discovery and stop.
- **Surface-level response:** Acknowledge their effort, then ask ONE deeper follow-up question that invites them to look beneath the surface: "That's a start. But what does that reveal about [deeper layer]?"
**Example Responses:**
- Thoughtful: "Beautiful insight. You've connected how [their response] embodies the principle of [highlight]. That awareness is transformative."
- Surface: "I hear you. But go deeper - if that's true on the surface, what does it reveal about what you truly value?"
**Rules:**
- Stay collaborative, never confrontational
- Questions reveal deep meaning, not test knowledge
- If unclear after 1-2 exchanges, gently guide with a reflective statement
- Your goal is wisdom and self-discovery, not debate
"""

Comments

Popular posts from this blog

Does God exist?

Does God exist? There is an emotional perspective to this question (called as religion) and then there is a logical perspective. Let us touch upon the latter one in this blog. If God doesn't exist, who created this universe? How are we conscious? Who designed everything so perfectly that we are alive? These are some of the typical questions of the "logical" class of people. But what they forget to take into consideration is that how old the life on earth really is compared to the age of the universe? The age of the universe is estimated to be around 13.8 billion years since the Big Bang. The life on earth started to exist from about 3.7 billion years ago. What does that mean? If there really was a creator, what took him/her so long to form life on earth? And if indeed he designed every position of the planet, comet and space-time fabric so perfectly, why was there an imperfection for about 10.1 billion years? What do you mean by "perfect"? Anything that supports...

What is mind?

What is mind? Think about it. Vow, isn't it an irony? How can you even think about thought? That's right. Do not think about it. Observe your thought. What is it exactly? Isn't it something that you say to yourself? It is basically a bundle of words. But wait, where do these words come from? And are you even controlling it? Can you control all of your thoughts? How do we find answers to these questions? Observe. You don't control most of your thoughts. They just happen subconsciously. Where do the words come from? From all of the information that you have collected till now from birth. Think of it like ChatGPT, someone is prompting and it is answering. Is ChatGPT aware and in control? No. It is answering what it knows, what it is trained for. Similar is our mind, except, the prompt is either the sensory inputs or the mind itself. Aren't we the best AI Language Model possible already? Not in terms of latency, but in terms of accuracy.

Top Prompting Techniques for LLMs

 1. Ask it to imitate the person you look up to. Example, MS Dhoni. You don't have to meet Dhoni to ask your question any more. LLM can answer your query pretending to be him. 2. GRWC - Specify Goal, Return format, Warnings, Context. 3. Reverse prompting - Give LLM a piece of art that you want to get inspiration from and ask it to design a prompt that will generate that art piece. Now, tune that prompt to your liking.  4. When reasoning, ask the LLM for a tree of thought to consider all possibilities and explore all options rationally. Think of what frameworks you apply when you think and replicate the same thing with the LLM.