from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores.chroma import ChromaVectorStore
from llama_index.core import StorageContext
from llama_index.core import Settings
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.gemini import Gemini
from llama_index.core.llms import ChatMessage
from llama_index.core.tools import QueryEngineTool
def multiply(a: float, b: float) -> float:
"""Multiply two numbers and returns the product"""
multiply_tool = FunctionTool.from_defaults(fn=multiply)
def add(a: float, b: float) -> float:
"""Add two numbers and returns the sum"""
documents = SimpleDirectoryReader("./data").load_data()
# initialize client, setting path to save data
db = chromadb.PersistentClient(path="./demo_01/chroma_db")
chroma_collection = db.get_or_create_collection("demo_01")
# assign chroma as the vector_store to the context
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
Settings.embed_model = HuggingFaceEmbedding(
model_name="BAAI/bge-small-en-v1.5"
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context
from llama_index.llms.gemini import Gemini
multiply_tool = FunctionTool.from_defaults(fn=multiply)
add_tool = FunctionTool.from_defaults(fn=add)
response = query_engine.query(
"What was the total amount of the 2023 Canadian federal budget?"
budget_tool = QueryEngineTool.from_defaults(
name="canadian_budget_2023",
description="A RAG engine with some basic facts about the 2023 Canadian federal budget.",
agent = ReActAgent.from_tools(
[multiply_tool, add_tool, budget_tool], verbose=True
"What is the total amount of the 2023 Canadian federal budget multiplied by 3? Go step by step, using a tool to do any math."