Skip to main content

Posts

What is Vector Database? Deep Dive with FAISS Example

Vector Database (Vector DB): A Deep Dive for ML/DL Engineers What is a Vector Database? A Vector Database (Vector DB) is a specialized type of database designed to efficiently store, index, and query high-dimensional vectors. These vectors often represent embeddings from deep learning models—semantic representations of data such as text, images, audio, or code. Unlike traditional relational databases that rely on exact key-based lookups or structured queries, vector databases are optimized for approximate or exact nearest neighbor (ANN or NNS) searches, which are fundamental to tasks such as semantic search, recommendation systems, anomaly detection, and generative AI retrieval-augmented generation (RAG). Core Components of a Vector Database A production-grade vector database typically comprises the following components: Embedding Store: A storage engine for high-dimensional vectors with metadata. Indexing Engine: Structures like HNSW, IVF, PQ, or ANNOY to support f...

Stateful LLM Chatbot Server with Gemini 2.5 Pro using LangGraph

  In this tutorial, we upgrade the   stateless chatbot server   by adding stateful memory support using   LangGraph . This enables more human-like, multi-turn conversations where the model remembers previous messages. Key Features of This Upgrade Powered by  Gemini 2.5 Pro  via LangChain's integration Uses  LangGraph's MemorySaver  for session memory Built with  Flask  and CORS enabled Maintains per-user conversation history using  thread_id Difference from the Stateless Version The main differences from the stateless version are: State Management:  Introduces a  State  class using  TypedDict  to track conversation history via  messages . LangGraph Integration:  Defines a stateful workflow using  StateGraph  and persists memory using  MemorySaver . Session Memory:  Associates chat sessions with a unique  thread_id  (e.g.,  user_124 ) using LangGraph's  config...

Stateful Chatbots with Gemini and LangGraph (LangChain)

When designing AI chatbots, a key architectural choice is whether to make your chatbot   stateless   or   stateful . Here's what that means and why it matters. Stateless Chatbots Stateless chatbots treat every user input as an isolated message. They do not remember previous interactions. This can be simple to implement but lacks conversational memory, making complex or context-driven dialogue harder to handle. Stateful Chatbots Stateful chatbots maintain memory across interactions, which allows them to provide personalized and coherent responses. They are ideal for tasks like long-form conversations, remembering user preferences, or task-driven agents. Building a Stateful Chatbot with Gemini + LangGraph Below is a complete example of how to build a stateful chatbot using  Gemini 2.5 Pro ,  LangChain , and  LangGraph . This chatbot can remember prior messages using a memory saver, and supports graph-based workflows for flexibility. # Import required librari...

How to Build a Simple LLM Chatbot Server with Google Gemini 2.5 Pro and LangChain

Introduction This post walks through how to implement a lightweight yet powerful chatbot backend using  Google Gemini 2.5 Pro  and  LangChain . It also covers how to deploy a chat-friendly frontend interface and understand the internal architecture powering this conversational AI. Whether you're prototyping or integrating LLMs into enterprise-scale apps, this pattern gives you a solid foundation to build on. Step 1: Install Dependencies Here's the minimal tech stack we’ll use: Python Packages pip install flask flask-cors langchain langchain-google-genai python-dotenv Make sure you have a .env file with your Google API key: GOOGLE_API_KEY=your_google_api_key_here Step 2: Chatbot Architecture Here’s a high-level diagram of how the system works: User (Web UI) │ ▼ HTTP POST /chat │ ▼ Flask API │ ▼ LangChain Prompt Template → Gemini 2.5 Pro (via Google Generative AI) │ ▼ Response → JSON → UI Frontend  sends a POST reque...

Using Gemini API in LangChain: Step-by-Step Tutorial

What is LangChain and Why Use It? LangChain  is an open-source framework that simplifies the use of  Large Language Models (LLMs)  like OpenAI, Gemini (Google), and others by adding structure, tools, and memory to help build real-world applications such as chatbots, assistants, agents, or AI-enhanced software. Why Use LangChain for LLM Projects? Chainable Components : Easily build pipelines combining prompts, LLMs, tools, and memory. Multi-Model Support : Work with Gemini, OpenAI, Anthropic, Hugging Face, etc. Built-in Templates : Manage prompts more effectively. Supports Multi-Turn Chat : Manage complex interactions with memory and roles. Tool and API Integration : Let the model interact with external APIs or functions. Let's Walk Through the Code: Gemini + LangChain I will break the code into  4 main parts , each showcasing different features of LangChain and Gemini API. Part 1: Basic Gemini API Call Using LangChain import os from dotenv import load_dotenv load_dot...

Getting Started with Google Gemini API

If you're just getting started with   Generative AI   and want to use   Google's Gemini models for free , you're in the right place. In this tutorial, I’ll walk you through everything you need to know to build your   first Gemini-powered application   using Python, including how to get a   free API key , install necessary libraries, and write code that interacts with Gemini’s generate_content() function. How to Get a Free Gemini API Key You’ll need a Google account for this. Go to the official  Google AI Studio . Sign in with your Google account. In the top-right corner, click on your profile and select  "Get API Key" . You’ll be redirected to Google Cloud's API Console. Create a  new API key  or use the existing one. Copy this key and keep it safe! You'll use it in your Python code. ** Important : Google provides  free quota  to use Gemini API. Make sure you check the  quota limits  for the free tier. Setting Up Your...