Skip to main content

Overview

In the Upsonic framework, a KnowledgeBase is a sophisticated orchestrator that manages the entire lifecycle of documents for RAG pipelines. It handles document ingestion, processing, vector storage, and retrieval operations. The KnowledgeBase integrates seamlessly with embedding providers, vector databases, loaders, and text splitters to provide intelligent knowledge retrieval capabilities.

KnowledgeBase Attributes

The KnowledgeBase class provides comprehensive configuration options to customize knowledge processing and retrieval behavior.

Core Attributes

AttributeTypeDescription
sourcesUnion[str, Path, List[Union[str, Path]]]Source identifiers (file paths, directory paths, or string content)
embedding_providerEmbeddingProviderProvider for creating vector embeddings from text
vectordbBaseVectorDBProviderVector database for storing and searching embeddings
splittersOptional[Union[BaseChunker, List[BaseChunker]]]Text chunking strategies for processing documents
loadersOptional[Union[BaseLoader, List[BaseLoader]]]Document loaders for different file types

Advanced Configuration

AttributeTypeDescription
nameOptional[str]Human-readable name for the knowledge base
use_casestrIntended use case for chunking optimization (“rag_retrieval”)
quality_preferencestrSpeed vs quality preference (“fast”, “balanced”, “quality”)
loader_configOptional[Dict[str, Any]]Configuration options specifically for loaders
splitter_configOptional[Dict[str, Any]]Configuration options specifically for splitters

Creating a KnowledgeBase

KnowledgeBase instances are created directly in code using the constructor. Each knowledge base can be customized with specific embedding providers, vector databases, loaders, and splitters to meet your exact requirements.

Basic KnowledgeBase Creation

KnowledgeBase with File Sources

KnowledgeBase with Directory Sources

Advanced KnowledgeBase Configuration

Custom Loaders and Splitters

Quality and Performance Optimization

Multiple KnowledgeBase Integration

Using Multiple Knowledge Sources

Domain-Specific Knowledge Bases

Vector Database Configuration

In-Memory Configuration

Persistent Local Configuration

Cloud Configuration

Embedding Provider Configuration

OpenAI Embeddings

Alternative Embedding Providers

Text Splitter Configuration

Recursive Text Splitter

Character-based Splitter

Document Loader Configuration

Text Loader

PDF Loader

CSV Loader

Practical Examples

Research Paper Analysis

Customer Support Knowledge Base

Code Documentation Assistant

Multiple Source Knowledge Integration

Best Practices

Performance Optimization

  1. Choose appropriate chunk sizes: Smaller chunks (200-500 tokens) for precise retrieval, larger chunks (1000+ tokens) for context.
  2. Use quality preferences: Set quality_preference="fast" for development, "quality" for production.
  3. Optimize vector database configuration: Use persistent storage for production, in-memory for testing.

Content Organization

  1. Organize sources logically: Group related documents together for better retrieval.
  2. Use descriptive names: Give your knowledge bases meaningful names for easier management.
  3. Consider multiple knowledge bases: Separate domain-specific knowledge for better organization.

Configuration Management

  1. Reuse configurations: Create configuration templates for consistent setups.
  2. Environment-specific settings: Use different configurations for development, testing, and production.
  3. Monitor performance: Track embedding costs and retrieval quality.

Complete Example