Study Assistant using self RAG

Built with a corrective RAG context and the ability to understand and answer based on the context. Added a chapter from the book “Introduction to Algorithms”.

  1. Created embeddings and stored in vector DB.
  2. Test the generated answer with respect to relevance and hallucinations. If not relevant or hallucinating then re-write the prompt to generate a more appropriate answer. This self-reflection technique is also called Corrective RAG or Corrective Self RAG.
  3. Created LangGraph to get the answers.

Some snapshots of the working model

Program flow (CRAG Architecture)

LangGraph design

A detailed 4 hour study plan when one can allocate 2 hours per day!

Study Planner based on context Based on the topics from the book, here’s a detailed 4-day study plan with 2 hours per day for a total of 8 hours: ### Day 1: Introduction and Basic Concepts 1. **Introduction to Binary Search Trees (BST)** – Definition and Properties – Use cases and applications 2. **Basic Operations** – Search – Insertion – Deletion **Time Allocation:** – Introduction to BST: 30 minutes – Search Operation: 30 minutes – Insertion Operation: 30 minutes – Deletion Operation: 30 minutes ### Day 2: Traversal Techniques and Balanced Trees 1. **Tree Traversal Methods** – In-order Traversal – Pre-order Traversal – Post-order Traversal 2. **Balanced Trees** – AVL Trees – Red-Black Trees **Time Allocation:** – In-order Traversal: 30 minutes – Pre-order Traversal: 30 minutes – Post-order Traversal: 30 minutes – AVL Trees: 30 minutes ### Day 3: Advanced Concepts and Analysis 1. **Advanced Operations** – Finding Minimum and Maximum – Successor and Predecessor 2. **Complexity Analysis** – Time Complexity of Operations – Space Complexity **Time Allocation:** – Finding Minimum and Maximum: 30 minutes – Successor and Predecessor: 30 minutes – Time Complexity Analysis: 30 minutes – Space Complexity Analysis: 30 minutes ### Day 4: Applications and Problem-Solving 1. **Real-world Applications** – Databases – File Systems – Network Routing 2. **Problem-Solving Session** – Practice Problems – Common Interview Questions **Time Allocation:** – Real-world Applications: 30 minutes – Practice Problems: 60 minutes – Common Interview Questions: 30 minutes This plan covers the essential topics and provides practice time to solidify your understanding. Feel free to adjust the time allocations based on your comfort with each topic.

Query 3: “Thanks! Can you create a cheat sheet for traversal mechanisms”

Binary Search Tree Traversal Mechanisms

1. Preorder Traversal

  • Description: In a preorder traversal, the nodes are recursively visited in this order: root, left subtree, right subtree.
  • Algorithm:
  1. Visit the root node.
  2. Traverse the left subtree in preorder.
  3. Traverse the right subtree in preorder.
  • Example:
        1
       / \
      2   3
     / \
    4   5

Preorder traversal of the above tree: 1, 2, 4, 5, 3

2. Inorder Traversal

  • Description: In an inorder traversal, the nodes are recursively visited in this order: left subtree, root, right subtree. This traversal prints the nodes in non-decreasing order.
  • Algorithm:
  1. Traverse the left subtree in inorder.
  2. Visit the root node.
  3. Traverse the right subtree in inorder.
  • Example:
        1
       / \
      2   3
     / \
    4   5

Inorder traversal of the above tree: 4, 2, 5, 1, 3

3. Postorder Traversal

  • Description: In a postorder traversal, the nodes are recursively visited in this order: left subtree, right subtree, root.
  • Algorithm:
  1. Traverse the left subtree in postorder.
  2. Traverse the right subtree in postorder.
  3. Visit the root node.
  • Example:
        1
       / \
      2   3
     / \
    4   5

Postorder traversal of the above tree: 4, 5, 2, 3, 1

4. Level Order Traversal

  • Description: In a level order traversal, the nodes are visited level by level from top to bottom and from left to right within each level.
  • Algorithm:
  1. Use a queue to keep track of nodes at each level.
  2. Start with the root node and enqueue it.
  3. While the queue is not empty, dequeue a node, visit it, and then enqueue its left and right children.
  • Example:
        1
       / \
      2   3
     / \
    4   5

Level order traversal of the above tree: 1, 2, 3, 4, 5

This cheat sheet covers the basic traversal mechanisms for binary search trees, providing a clear and concise reference for each type of traversal.

Langsmith snapshots

References

I used some of the examples in Langgraph to design this https://github.com/langchain-ai/langgraph/tree/main/examples

Leave a Reply