Skip to main content
Knowledge bases enable Retrieval Augmented Generation (RAG) by storing and querying documents. Agents can use knowledge bases to answer questions based on your documents, websites, and other content.

Quick Start

from lyzr import Studio

studio = Studio(api_key="your-api-key")

# Create a knowledge base
kb = studio.create_knowledge_base(
    name="product_docs",
    vector_store="qdrant",
    embedding_model="text-embedding-3-large"
)

# Add documents
kb.add_pdf("manual.pdf")
kb.add_website("https://docs.example.com", max_pages=50)

# Create an agent with the knowledge base
agent = studio.create_agent(
    name="Support Bot",
    provider="gpt-4o",
    role="Customer support",
    goal="Answer questions using documentation",
    instructions="Use the knowledge base to answer questions accurately"
)

# Query with the knowledge base
response = agent.run(
    "How do I reset my password?",
    knowledge_bases=[kb]
)
print(response.response)

What is a Knowledge Base?

A knowledge base is a vector database that stores your documents as embeddings. When an agent receives a question, it:
  1. Searches the knowledge base for relevant content
  2. Retrieves the most relevant chunks
  3. Generates a response using the retrieved context
This is called Retrieval Augmented Generation (RAG).

Supported Document Types

TypeMethodDescription
PDFadd_pdf()PDF documents
DOCXadd_docx()Word documents
TXTadd_txt()Plain text files
Websiteadd_website()Web pages with crawling
Textadd_text()Raw text strings

Vector Store Providers

ProviderIDDescription
QdrantqdrantDefault, high-performance vector database
WeaviateweaviateOpen-source vector search engine
PG Vectorpg_vectorPostgreSQL with vector extension
MilvusmilvusScalable vector database
NeptuneneptuneAmazon Neptune graph database

Key Operations

Create

kb = studio.create_knowledge_base(
    name="my_kb",
    vector_store="qdrant"
)

Add Documents

kb.add_pdf("document.pdf")
kb.add_website("https://example.com")
kb.add_text("Custom content", source="custom")

Query

results = kb.query("search term", top_k=5)
for result in results:
    print(f"{result.score:.2f}: {result.text}")

Use with Agent

response = agent.run(
    "What is the return policy?",
    knowledge_bases=[kb]
)

Retrieval Types

TypeDescription
basicStandard vector similarity search
mmrMaximal Marginal Relevance (diverse results)
hydeHypothetical Document Embeddings
time_awareTime-decay weighted retrieval

Next Steps

Creating Knowledge Bases

Learn all creation options and configuration

Adding Documents

Add PDFs, websites, and other content

Querying

Search and retrieve from knowledge bases

Managing

Update, delete, and manage documents