Skip to main content

Knowledge

RAG-powered knowledge management with document processing, vector storage, and semantic search.

Quick Start

Usage Forms Table

Presets & Options

Supported Sources

Precedence Ladder

Resolution Order: Instance > Config > Array > Dict > String > Bool > DefaultWhen you pass knowledge=, the resolver checks in this order:
  1. Instance - Knowledge instance? Use as-is
  2. Config - KnowledgeConfig instance? Use as-is
  3. Array - List of sources? Process as file paths/URLs
  4. Dict - {"key": value}? Convert to config
  5. String - Preset or single source? Look up or use as source
  6. Bool - True? Use defaults. False? Disable

Classes

Knowledge

Chunking Strategies

CustomMemory

A specialized memory class that bypasses LLM usage for simple fact storage.

Chunking

Unified interface for various text chunking strategies using the chonkie library.

Parameters

  • chunker_type: str = 'recursive' - Type of chunking strategy
  • chunk_size: int = 512 - Maximum size of each chunk
  • chunk_overlap: int = 50 - Overlap between chunks
  • tokenizer: Optional[Any] = None - Custom tokenizer (defaults to GPT-2)
  • embedding_model: Optional[Any] = None - Embedding model for semantic chunking

Methods

  • chunk(text: str) → List[Chunk] - Split text into chunks using configured strategy

Configuration

Vector Store Configuration

Chunking Strategies

1. Token Chunker ('token')

Splits text by token count with overlapping windows.

2. Sentence Chunker ('sentence')

Splits text by sentences while respecting chunk size.

3. Recursive Chunker ('recursive') - Default

Hierarchical splitting with multiple separators.

4. Semantic Chunker ('semantic')

Groups semantically similar content together.

5. SDPM Chunker ('sdpm')

Semantic Double-Pass Merge for optimal chunking.

6. Late Chunker ('late')

Optimized for retrieval performance with late interaction.

Usage Examples

Basic Knowledge Management

Agent Integration

Advanced Configuration

Scoped Knowledge Retrieval

Supported File Types

  • Documents: PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX
  • Text: TXT, MD, CSV, JSON, XML, HTML
  • Images: JPG, PNG, GIF, BMP, SVG
  • Audio: MP3, WAV, M4A (transcription support)
  • Archives: ZIP (planned)

Performance Optimization

  1. Batch Processing - Add multiple files in one call for efficiency
  2. Chunk Size - Larger chunks for narrative content, smaller for technical
  3. Reranking - Disable for faster search when precision isn’t critical
  4. Embedding Cache - Reuse embeddings for duplicate content

Best Practices

  1. Choose Appropriate Chunking - Semantic for varied content, recursive for structured
  2. Set Meaningful Metadata - Use metadata for filtering and organization
  3. Regular Cleanup - Delete outdated knowledge to maintain relevance
  4. Monitor Storage - Check vector store size for large knowledge bases
  5. Test Retrieval Quality - Verify search results match expectations ======= title: “Knowledge” sidebarTitle: “Knowledge” description: “Knowledge base management and vector storage for RAG applications” icon: “book”

Overview

The Knowledge module provides powerful knowledge base management and vector storage capabilities for building RAG (Retrieval-Augmented Generation) applications. It supports multiple file formats, various chunking strategies, and semantic search with optional reranking.

Quick Start

1
Install praisonaiagents
2
Import and initialize Knowledge
3
Advanced configuration

Key Concepts

API Reference

Constructor

Parameters

str
default:"knowledge_base"
Name of the ChromaDB collection
Optional[str]
Path for persistent storage (defaults to .praison/chroma_db)
int
default:"1000"
Size of text chunks for processing
int
default:"200"
Overlap between consecutive chunks
str
default:"recursive"
Strategy for splitting text (see Chunking Strategies section)
str
default:"all-MiniLM-L6-v2"
Model for generating embeddings
bool
default:"False"
Whether to use reranking for search results
str
default:"ms-marco-MiniLM-L-6-v2"
Model for reranking search results

Methods

add()

Add content to the knowledge base from various sources.
Parameters:
  • source - File path, URL, or direct text content
Returns:
  • bool - Success status
Supported formats:
  • Documents: PDF, DOCX, PPTX
  • Spreadsheets: XLSX, XLS, CSV
  • Images: PNG, JPG, JPEG
  • Web: HTML, URLs
  • Text: TXT, MD, Python, JavaScript, etc.
Search the knowledge base for relevant content.
Parameters:
  • query - Search query
  • limit - Maximum number of results
Returns:
  • List of dictionaries containing:
    • text - Content chunk
    • source - Original source
    • score - Relevance score
    • metadata - Additional metadata

get_context()

Get formatted context for a query (useful for agents).
Parameters:
  • query - Search query
  • max_results - Maximum results to include
Returns:
  • Formatted string with relevant context

clear()

Clear all content from the knowledge base.

get_stats()

Get statistics about the knowledge base.
Returns:
  • Dictionary with:
    • total_chunks - Number of stored chunks
    • sources - List of unique sources
    • collection_name - Name of the collection
    • storage_path - Path to storage

Chunking Strategies

The knowledge module supports multiple chunking strategies for different use cases:
Splits text based on token count. Best for:
  • Consistent chunk sizes for LLM processing
  • Language model token limit management

Integration Examples

With Agents

RAG Application

Multi-Agent Knowledge Sharing

Custom Processing Pipeline

Best Practices

Document Preparation

  • Clean documents before adding (remove headers/footers if needed)
  • Use appropriate formats - PDF for formatted docs, MD for technical docs
  • Structure content with clear headings and sections
  • Include metadata in document names or content

Chunking Strategy

  • Token-based: When working with token-limited LLMs
  • Sentence-based: For Q&A systems needing complete thoughts
  • Recursive: General purpose, good default choice
  • Semantic: For documents with multiple distinct topics
  • SDPM: For academic or highly structured content
  • Late chunking: When retrieval accuracy is critical

Search Optimization

  • Use reranking for better relevance in large knowledge bases
  • Tune chunk size - smaller for precise retrieval, larger for context
  • Optimize queries - use clear, specific search terms
  • Limit results appropriately to balance relevance and coverage

Storage Management

  • Use meaningful collection names for different knowledge domains
  • Implement cleanup strategies for growing knowledge bases
  • Monitor storage size and implement archival if needed
  • Backup important collections regularly

Performance Considerations

Embedding Models

The choice of embedding model affects both quality and performance:

Reranking Impact

Scaling Considerations

For large knowledge bases:
  1. Use appropriate chunk sizes - Larger chunks reduce total count
  2. Implement batch processing for adding multiple documents
  3. Consider sharding collections by domain or time period
  4. Monitor memory usage with embedding models
  5. Use persistent storage to avoid reprocessing

Troubleshooting

Common issues and solutions:

Complete Example