A Coding Implementation of an Intelligent AI Assistant with Jina Search, LangChain, and Gemini for Real-Time Information Retrieval

In this tutorial, we demonstrate how to build an intelligent AI assistant by integrating LangChain, Gemini 2.0 Flash, and Jina Search tools. By combining the capabilities of a powerful large language model (LLM) with an external search API, we create an assistant that can provide up-to-date information with citations. This step-by-step tutorial walks through setting […] The post A Coding Implementation of an Intelligent AI Assistant with Jina Search, LangChain, and Gemini for Real-Time Information Retrieval appeared first on MarkTechPost.

Jun 1, 2025 - 21:30
 0
A Coding Implementation of an Intelligent AI Assistant with Jina Search, LangChain, and Gemini for Real-Time Information Retrieval

In this tutorial, we demonstrate how to build an intelligent AI assistant by integrating LangChain, Gemini 2.0 Flash, and Jina Search tools. By combining the capabilities of a powerful large language model (LLM) with an external search API, we create an assistant that can provide up-to-date information with citations. This step-by-step tutorial walks through setting up API keys, installing necessary libraries, binding tools to the Gemini model, and building a custom LangChain that dynamically calls external tools when the model requires fresh or specific information. By the end of this tutorial, we will have a fully functional, interactive AI assistant that can respond to user queries with accurate, current, and well-sourced answers.

%pip install --quiet -U "langchain-community>=0.2.16" langchain langchain-google-genai

We install the required Python packages for this project. It includes the LangChain framework for building AI applications, LangChain Community tools (version 0.2.16 or higher), and LangChain’s integration with Google Gemini models. These packages enable seamless use of Gemini models and external tools within LangChain pipelines.

import getpass
import os
import json
from typing import Dict, Any

We incorporate essential modules into the project. Getpass allows securely entering API keys without displaying them on the screen, while os helps manage environment variables and file paths. JSON is used for handling JSON data structures, and typing provides type hints for variables, such as dictionaries and function arguments, ensuring better code readability and maintainability.

if not os.environ.get("JINA_API_KEY"):
    os.environ["JINA_API_KEY"] = getpass.getpass("Enter your Jina API key: ")


if not os.environ.get("GOOGLE_API_KEY"):
    os.environ["GOOGLE_API_KEY"] = getpass.getpass("Enter your Google/Gemini API key: ")

We ensure that the necessary API keys for Jina and Google Gemini are set as environment variables. Suppose the keys are not already defined in the environment. In that case, the script prompts the user to enter them securely using the getpass module, keeping the keys hidden from view for security purposes. This approach enables seamless access to these services without requiring the hardcoding of sensitive information in the code.

from langchain_community.tools import JinaSearch
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableConfig, chain
from langchain_core.messages import HumanMessage, AIMessage, ToolMessage


print("                        </div>
                                            <div class=
                            
                                Read More