Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:ANative Lab EvoAgentX RAGEngine

From Leeroopedia
Knowledge Sources
Domains RAG, NLP, Retrieval
Last Updated 2026-10-21 00:00 GMT

Overview

Concrete tool for building Retrieval-Augmented Generation pipelines with configurable readers, chunkers, embeddings, indexing, retrieval, and postprocessing.

Description

The RAGEngine class orchestrates the full RAG pipeline: document reading (via LlamaIndex-based readers), chunking (simple, semantic, or hierarchical), embedding (OpenAI, HuggingFace, Ollama), indexing (vector or graph), retrieval (vector similarity or graph-based), and postprocessing (reranking). It manages per-corpus index and retriever registries, supports both text and multimodal modalities, and provides persistence via `save()` / `load()` to files or database.

Usage

  • Document ingestion: Call `read()` to load files, then `add()` to index chunks into a vector or graph store.
  • Query and retrieve: Call `query()` with a query string or `Query` object to retrieve relevant chunks with similarity scores.
  • Persistence: Save indices to JSONL/database via `save()` and reload via `load()`.
  • Multimodal RAG: Set `modality="multimodal"` in `RAGConfig` for image-based retrieval.

Code Reference

Source Location

  • Repository: EvoAgentX
  • File: evoagentx/rag/rag.py (L25-702)

Signature

class RAGEngine:
    def __init__(self, config: RAGConfig, storage_handler: StorageHandler, llm: Optional[BaseLLM] = None)

    def read(self, file_paths: Union[str, Sequence[str]], exclude_files=None, filter_file_by_suffix=None, merge_by_file=False, show_progress=False, corpus_id: str = None) -> Corpus
    def add(self, index_type: str, nodes: Union[Corpus, List], corpus_id: str = None) -> Sequence[str]
    def delete(self, corpus_id: str, index_type: Optional[str] = None, node_ids=None, metadata_filters=None) -> None
    def clear(self, corpus_id: Optional[str] = None) -> None
    def save(self, output_path: Optional[str] = None, corpus_id: Optional[str] = None, index_type: Optional[str] = None, table: Optional[str] = None, graph_exported: bool = False) -> None
    def load(self, source: Optional[str] = None, corpus_id: Optional[str] = None, index_type: Optional[str] = None, table: Optional[str] = None) -> None
    def query(self, query: Union[str, Query], corpus_id: Optional[str] = None, query_transforms: Optional[List] = None) -> RagResult
    async def query_async(self, query: Union[str, Query], corpus_id: Optional[str] = None, query_transforms: Optional[List] = None) -> RagResult

Import

from evoagentx.rag.rag import RAGEngine

I/O Contract

Inputs

Name Type Required Description
config RAGConfig Yes Pipeline configuration for all stages
storage_handler StorageHandler Yes Storage backend (DB, vector, graph)
llm BaseLLM No LLM for entity extraction (graph index)
file_paths List[str] Yes (for read) File or directory paths
index_type str Yes (for add) "VECTOR" or "GRAPH"
query Query Yes (for query) Query string or Query object

Outputs

Name Type Description
read returns Corpus Chunked corpus from documents
add returns Sequence[str] Node IDs inserted into index
query returns RagResult Retrieved chunks with scores and metadata

Usage Examples

Full RAG Pipeline

from evoagentx.rag.rag import RAGEngine
from evoagentx.rag.rag_config import RAGConfig, ChunkerConfig, EmbeddingConfig, RetrievalConfig
from evoagentx.storages.base import StorageHandler
from evoagentx.storages.storages_config import StoreConfig, DBConfig, VectorStoreConfig

# 1. Configure storage
storage_handler = StorageHandler(storageConfig=StoreConfig(
    dbConfig=DBConfig(db_name="sqlite", path="./rag.db"),
    vectorConfig=VectorStoreConfig(vector_name="faiss", dimensions=1536),
))

# 2. Configure RAG pipeline
rag_config = RAGConfig(
    chunker=ChunkerConfig(strategy="SIMPLE", chunk_size=512),
    embedding=EmbeddingConfig(provider="OPENAI", model_name="text-embedding-ada-002", api_key="sk-..."),
    retrieval=RetrievalConfig(top_k=5, similarity_cutoff=0.7),
)

# 3. Initialize engine
engine = RAGEngine(config=rag_config, storage_handler=storage_handler)

# 4. Ingest documents
corpus = engine.read(file_paths="./docs/")
engine.add(index_type="VECTOR", nodes=corpus, corpus_id="my_corpus")

# 5. Query
result = engine.query(query="What is the main topic?", corpus_id="my_corpus")
for chunk, score in zip(result.corpus.chunks, result.scores):
    print(f"Score: {score:.3f} | {chunk.text[:100]}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment