Building a Real-Time AI Assistant with LangChain, Gemini 2.0 Flash, and Jina Search for Up-to-Date Information Retrieval
Build an AI assistant by integrating LangChain, Gemini 2.0 Flash, and Jina Search for up-to-date, cited information. It dynamically calls external tools for accurate, current responses.

A Coding Implementation of an Intelligent AI Assistant with Jina Search, LangChain, and Gemini for Real-Time Information Retrieval
This tutorial walks through building an intelligent AI assistant by integrating LangChain, Gemini 2.0 Flash, and Jina Search. By combining a powerful large language model (LLM) with an external search API, the assistant delivers up-to-date information complete with citations.
The process covers setting up API keys, installing necessary libraries, binding tools to the Gemini model, and creating a custom LangChain pipeline that dynamically calls external tools when fresh or specific information is needed. The end result is an interactive AI assistant capable of accurate, current, and well-sourced responses.
Setting Up the Environment and Required Packages
Start by installing Python packages including the LangChain framework, LangChain Community tools (version 0.2.16+), and LangChain’s integration with Google Gemini models. These packages enable seamless use of Gemini models alongside external tools within LangChain pipelines.
Essential Python modules such as getpass (for secure API key input), os (for environment variable handling), json (for JSON data processing), and typing (for type hints) are incorporated to maintain code clarity and security.
Managing API Keys Securely
Ensure that API keys for Jina and Google Gemini are stored as environment variables. If missing, the script prompts for secure input using getpass
, hiding keys from on-screen display. This avoids hardcoding sensitive credentials and maintains security best practices.
Integrating LangChain Components and Tools
Key classes and modules are imported from LangChain, including the JinaSearch
tool for web search, the ChatGoogleGenerativeAI
model for Gemini access, and core classes like ChatPromptTemplate
, RunnableConfig
, and message types (HumanMessage
, AIMessage
, ToolMessage
).
This setup prepares the AI assistant to integrate external tools dynamically, enabling information retrieval beyond the model’s static knowledge.
Testing and Initializing Tools
The Jina Search tool is initialized and tested with a sample query (“what is langgraph”). The test verifies that the search functionality works correctly before deeper integration.
Similarly, the Gemini 2.0 Flash model is initialized with a low temperature setting (0.1) for consistent responses, and system messages are converted to human-readable prompts for better interaction with Gemini’s API.
Designing the AI Prompt Template
A ChatPromptTemplate
is defined to guide the AI’s responses. It includes:
- A system message explaining the assistant’s role
- A placeholder for human user input
- A placeholder for tool-generated messages
This structure ensures responses are helpful, informative, and incorporate search results smoothly.
Binding Tools to the Gemini Model
The Jina Search tool is bound to the Gemini model using bind_tools()
. This enables the model to invoke web search as needed during conversations. The main chain combines the prompt template and the Gemini model enhanced with tool access, creating a streamlined workflow.
A helper function formats search results for clarity, making it easier for users to understand retrieved information.
Building the Enhanced Search Chain
Using LangChain’s @chain
decorator, an enhanced search chain is defined. It processes user input through the main chain and checks if tool calls are suggested by the AI.
If tool calls exist, the search is executed, results are wrapped as ToolMessage
objects, and the chain reinvokes with these results to produce a final, enriched response. If not, it returns the AI’s initial reply directly.
Validating the AI Assistant
The test_search_chain()
function runs multiple test queries covering various topics such as AI, LangChain, and tool usage. It prints out results and indicates whether tool calls were utilized, confirming the assistant’s ability to trigger web searches and respond effectively.
Interactive Usage
When executed as a script, the assistant first runs its test suite. Afterwards, it enters an interactive mode allowing users to type custom questions. The assistant responds with AI-generated answers enhanced by dynamic search results when appropriate. The session continues until the user types ‘quit’, ‘exit’, or ‘bye’.
Conclusion
This project demonstrates how to build an AI assistant that extends static language model knowledge by integrating real-time web search capabilities. Combining LangChain’s modular framework, Gemini 2.0 Flash’s generative skills, and Jina Search’s web querying creates a system that provides accurate, up-to-date, and well-sourced information.
You can expand this foundation by adding more tools, customizing prompts, or deploying the assistant as an API or web app to suit broader applications.
For those interested in enhancing AI skills further, Complete AI Training’s latest AI courses offer practical guidance on AI development and integration techniques.