llama-farm

rag-skills

810
45
# Install this skill:
npx skills add llama-farm/llamafarm --skill "rag-skills"

Install specific skill from multi-skill repository

# Description

RAG-specific best practices for LlamaIndex, ChromaDB, and Celery workers. Covers ingestion, retrieval, embeddings, and performance.

# SKILL.md


name: rag-skills
description: RAG-specific best practices for LlamaIndex, ChromaDB, and Celery workers. Covers ingestion, retrieval, embeddings, and performance.
allowed-tools: Read, Grep, Glob
user-invocable: false


RAG Skills for LlamaFarm

Framework-specific patterns and code review checklists for the RAG component.

Extends: python-skills - All Python best practices apply here.

Component Overview

Aspect Technology Version
Python Python 3.11+
Document Processing LlamaIndex 0.13+
Vector Storage ChromaDB 1.0+
Task Queue Celery 5.5+
Embeddings Universal/Ollama/OpenAI Multiple

Directory Structure

rag/
β”œβ”€β”€ api.py                 # Search and database APIs
β”œβ”€β”€ celery_app.py          # Celery configuration
β”œβ”€β”€ main.py                # Entry point
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ base.py            # Document, Component, Pipeline ABCs
β”‚   β”œβ”€β”€ factories.py       # Component factories
β”‚   β”œβ”€β”€ ingest_handler.py  # File ingestion with safety checks
β”‚   β”œβ”€β”€ blob_processor.py  # Binary file processing
β”‚   β”œβ”€β”€ settings.py        # Pydantic settings
β”‚   └── logging.py         # RAGStructLogger
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ embedders/         # Embedding providers
β”‚   β”œβ”€β”€ extractors/        # Metadata extractors
β”‚   β”œβ”€β”€ parsers/           # Document parsers (LlamaIndex)
β”‚   β”œβ”€β”€ retrievers/        # Retrieval strategies
β”‚   └── stores/            # Vector stores (ChromaDB, FAISS)
β”œβ”€β”€ tasks/                 # Celery tasks
β”‚   β”œβ”€β”€ ingest_tasks.py    # File ingestion
β”‚   β”œβ”€β”€ search_tasks.py    # Database search
β”‚   β”œβ”€β”€ query_tasks.py     # Complex queries
β”‚   β”œβ”€β”€ health_tasks.py    # Health checks
β”‚   └── stats_tasks.py     # Statistics
└── utils/
    └── embedding_safety.py  # Circuit breaker, validation

Quick Reference

Topic File Key Points
LlamaIndex llamaindex.md Document parsing, chunking, node conversion
ChromaDB chromadb.md Collections, embeddings, distance metrics
Celery celery.md Task routing, error handling, worker config
Performance performance.md Batching, caching, deduplication

Core Patterns

Document Dataclass

from dataclasses import dataclass, field
from typing import Any

@dataclass
class Document:
    content: str
    metadata: dict[str, Any] = field(default_factory=dict)
    id: str = field(default_factory=lambda: str(uuid.uuid4()))
    source: str | None = None
    embeddings: list[float] | None = None

Component Abstract Base Class

from abc import ABC, abstractmethod

class Component(ABC):
    def __init__(
        self,
        name: str | None = None,
        config: dict[str, Any] | None = None,
        project_dir: Path | None = None,
    ):
        self.name = name or self.__class__.__name__
        self.config = config or {}
        self.logger = RAGStructLogger(__name__).bind(name=self.name)
        self.project_dir = project_dir

    @abstractmethod
    def process(self, documents: list[Document]) -> ProcessingResult:
        pass

Retrieval Strategy Pattern

class RetrievalStrategy(Component, ABC):
    @abstractmethod
    def retrieve(
        self,
        query_embedding: list[float],
        vector_store,
        top_k: int = 5,
        **kwargs
    ) -> RetrievalResult:
        pass

    @abstractmethod
    def supports_vector_store(self, vector_store_type: str) -> bool:
        pass

Embedder with Circuit Breaker

class Embedder(Component):
    DEFAULT_FAILURE_THRESHOLD = 5
    DEFAULT_RESET_TIMEOUT = 60.0

    def __init__(self, ...):
        super().__init__(...)
        self._circuit_breaker = CircuitBreaker(
            failure_threshold=config.get("failure_threshold", 5),
            reset_timeout=config.get("reset_timeout", 60.0),
        )
        self._fail_fast = config.get("fail_fast", True)

    def embed_text(self, text: str) -> list[float]:
        self.check_circuit_breaker()
        try:
            embedding = self._call_embedding_api(text)
            self.record_success()
            return embedding
        except Exception as e:
            self.record_failure(e)
            if self._fail_fast:
                raise EmbedderUnavailableError(str(e)) from e
            return [0.0] * self.get_embedding_dimension()

Review Checklist Summary

When reviewing RAG code:

  1. LlamaIndex (Medium priority)
  2. Proper chunking configuration
  3. Metadata preservation during parsing
  4. Error handling for unsupported formats

  5. ChromaDB (High priority)

  6. Thread-safe client access
  7. Proper distance metric selection
  8. Metadata type compatibility

  9. Celery (High priority)

  10. Task routing to correct queue
  11. Error logging with context
  12. Proper serialization

  13. Performance (Medium priority)

  14. Batch processing for embeddings
  15. Deduplication enabled
  16. Appropriate caching

See individual topic files for detailed checklists with grep patterns.

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.