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:- Instance - Knowledge instance? Use as-is
- Config - KnowledgeConfig instance? Use as-is
- Array - List of sources? Process as file paths/URLs
- Dict -
{"key": value}? Convert to config - String - Preset or single source? Look up or use as source
- 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 strategychunk_size: int = 512- Maximum size of each chunkchunk_overlap: int = 50- Overlap between chunkstokenizer: 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
- Batch Processing - Add multiple files in one call for efficiency
- Chunk Size - Larger chunks for narrative content, smaller for technical
- Reranking - Disable for faster search when precision isn’t critical
- Embedding Cache - Reuse embeddings for duplicate content
Best Practices
- Choose Appropriate Chunking - Semantic for varied content, recursive for structured
- Set Meaningful Metadata - Use metadata for filtering and organization
- Regular Cleanup - Delete outdated knowledge to maintain relevance
- Monitor Storage - Check vector store size for large knowledge bases
- 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.source- File path, URL, or direct text content
bool- Success status
- Documents: PDF, DOCX, PPTX
- Spreadsheets: XLSX, XLS, CSV
- Images: PNG, JPG, JPEG
- Web: HTML, URLs
- Text: TXT, MD, Python, JavaScript, etc.
search()
Search the knowledge base for relevant content.query- Search querylimit- Maximum number of results
- List of dictionaries containing:
text- Content chunksource- Original sourcescore- Relevance scoremetadata- Additional metadata
get_context()
Get formatted context for a query (useful for agents).query- Search querymax_results- Maximum results to include
- Formatted string with relevant context
clear()
Clear all content from the knowledge base.get_stats()
Get statistics about the knowledge base.- Dictionary with:
total_chunks- Number of stored chunkssources- List of unique sourcescollection_name- Name of the collectionstorage_path- Path to storage
Chunking Strategies
The knowledge module supports multiple chunking strategies for different use cases:- Token-based
- Sentence-based
- Recursive
- Semantic
- SDPM
- Late Chunking
- 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:- Use appropriate chunk sizes - Larger chunks reduce total count
- Implement batch processing for adding multiple documents
- Consider sharding collections by domain or time period
- Monitor memory usage with embedding models
- Use persistent storage to avoid reprocessing

