Skip to main content
Create a knowledge base, add documents, and use it with an agent.
1

Create the agent

basic_rag.py
import asyncio
from definable.agent import Agent
from definable.knowledge import Knowledge
from definable.vectordb import InMemoryVectorDB

# Create knowledge base
knowledge = Knowledge(vector_db=InMemoryVectorDB())

# Add documents
knowledge.add("Definable is a Python framework for building AI agents.")
knowledge.add("It supports 10 LLM providers including OpenAI, Anthropic, and Google.")
knowledge.add("Agents can use tools, knowledge, memory, middleware, and tracing.")
knowledge.add("The @tool decorator converts Python functions into agent-callable tools.")

# Create agent with knowledge
agent = Agent(
    model="gpt-4o",
    knowledge=knowledge,
    instructions="Answer questions using the provided knowledge base. Cite specific facts.",
)

async def main():
    output = await agent.arun("What LLM providers does Definable support?")
    print(output.content)

asyncio.run(main())
2

Install and run

pip install definable
python basic_rag.py

Path Shorthand

Load an entire directory of documents:
agent = Agent(model="gpt-4o", knowledge="./docs/")
This auto-configures InMemoryVectorDB + OpenAIEmbedder + RecursiveChunker and recursively loads all supported files.