Ragfish Logo
Get In Touch
Ragfish Logo

Book a Demo

Error Handling

Errors are an expected part of any AI application.

A Ragfish application can interact with multiple components, including AI providers, vector stores, connectors, document processors, and external services. Failures can therefore occur at different stages of the application lifecycle.

Ragfish provides a consistent framework architecture so that applications can identify and handle these failures appropriately.

Where Errors Can Occur

A typical Ragfish request can pass through several components:

User Request
     │
     ▼
   Chat
     │
     ▼
 Retriever
     │
     ▼
Vector Store
     │
     ▼
AI Provider
     │
     ▼
 Response


An error can occur at any of these stages.

For example:

    1. Invalid configuration

    2. Missing API credentials

    3. AI provider failure

    4. Vector store connection failure

    5. Retrieval failure

    6. Invalid input

    7. Document ingestion failure

    8. Network failure

Error Handling Philosophy

Ragfish follows a modular architecture, so errors should be handled at the appropriate layer.

                         Application
                              │
                              ▼
                        Ragfish Core
                              │
              ┌───────────────┼───────────────┐
              ▼               ▼               ▼
             LLM          Retriever       Connector
              │               │               │
              ▼               ▼               ▼
           Provider        Vector DB         Source



The application should distinguish between:

    1. Errors that can be corrected by the user.

    2. Errors that require configuration changes.

    3. Temporary external-service failures.

    4. Programming or implementation errors.

Configuration Errors

Configuration errors commonly occur when required settings are missing or invalid.

For example, an AI provider may require an API key:

Settings.llm = new OpenAILLM({
  apiKey: process.env.OPENAI_API_KEY
});

If the required environment variable is missing, the application should identify the configuration problem before attempting to process user requests.

A recommended startup check is:

if (!process.env.OPENAI_API_KEY) {
  throw new Error("OPENAI_API_KEY is not configured");
}

This allows configuration problems to be detected early.

AI Provider Errors

AI provider requests depend on external services.

Possible failures include:

    1. Invalid credentials

    2. Rate limits

    3. Network failures

    4. Provider outages

    5. Invalid model configuration

    6. Request limits

Your application should handle provider failures gracefully rather than exposing internal errors directly to end users.

For example:

try {
  const response = await chat.message(
    "What is Ragfish?"
  );

  console.log(response);
} catch (error) {
  console.error("AI request failed:", error);
}

The exact error types available depend on the provider package being used.

Vector Store Errors

Retrieval depends on the configured vector store.

For example, a Qdrant-based application may fail if the vector database is unavailable.

const vectorStore = new QdrantVectorStore({
  url: process.env.QDRANT_URL,
  apiKey: process.env.QDRANT_API_KEY
});

Possible failures include:

    1. Invalid connection details

    2. Authentication failure

    3. Collection not found

    4. Network failure

    5. Search failure

    6. Service unavailable

These errors should be handled separately from AI provider errors because the appropriate recovery strategy may be different.

Retrieval Errors

A retrieval operation can fail even when the language model is available.

For example:

User Question
      │
      ▼
   Retriever
      │
      X
      │
 Retrieval Error


Applications should avoid silently generating an answer when the required knowledge could not be retrieved.

Depending on the application, you may choose to:

    1. Retry the retrieval operation.

    2. Return a clear error.

    3. Ask the user to try again.

    4. Fall back to another retrieval strategy.

    5. Log the failure for investigation.

Ingestion Errors

Errors can also occur while importing knowledge.

For example:

Knowledge Source
      │
      ▼
   Ingestion
      │
      X
      │
 Ingestion Error


Common causes include:

    1. Unsupported files

    2. Invalid document content

    3. Corrupted files

    4. Missing permissions

    5. Connector failures

    6. External service errors

For large ingestion jobs, it is often better to isolate failed items rather than allowing one failed document to stop the entire process.

Input Validation

Applications should validate user input before sending it through the Ragfish pipeline.

For example:

const question = input.trim();

if (!question) {
  throw new Error("Question cannot be empty");
}

const response = await chat.message(question);

Input validation helps prevent unnecessary model and retrieval requests.

Handling Errors at Application Boundaries

Errors should generally be handled at the application boundary.

For example, in an API application:

HTTP Request
     │
     ▼
Application Route
     │
     ▼
Ragfish
     │
     X
     │
    Error
     │
     ▼
Application Error Handler
     │
     ▼
Safe API Response

Internal error details should be logged for developers but should not necessarily be exposed directly to end users.

Logging

Logging is important when diagnosing failures in production.

A useful error log should contain enough context to identify the failed operation.

For example:

try {
  const response = await chat.message(question);

  return response;
} catch (error) {
  console.error("Chat request failed", {
    error,
    question
  });

  throw error;
}

Avoid logging sensitive information such as API keys, passwords, or confidential document content.

Retry Strategies

Some failures are temporary.

For example:

Request
  │
  ▼
Provider
  │
  X
Temporary Failure
  │
  ▼
Retry
  │
  ▼
Success


Retries can be useful for transient network or service failures.

However, retries should be used carefully. Repeatedly retrying permanent failures can increase latency and unnecessary costs.

Consider:

    1. Maximum retry attempts

    2. Retry delays

    3. Exponential backoff

    4. Which errors are safe to retry

Graceful Failure

AI applications should fail gracefully.

Instead of returning an internal exception directly to the user:

Internal vector database connection error:

ECONNREFUSED...

the application can provide a safe message:

We couldn't retrieve the requested information.

Please try again shortly.

The detailed error can remain in the application logs for troubleshooting.

Error Handling by Layer

A useful way to organize error handling is by framework layer.

Layer

Example Failure

Typical Response

Configuration

Missing API key

Fix configuration

Connector

Source unavailable

Retry or report source failure

Ingestion

Invalid document

Skip or report failed item

Chunking

Invalid content

Validate or reject input

Retrieval

Vector store unavailable

Retry or fail gracefully

LLM

Provider error

Retry when appropriate

Application

Invalid user input

Validate and return a safe error

Development vs Production

Error handling requirements are different during development and production.

Development

During development, detailed errors are useful for debugging.

console.error(error);

Production

In production:

    1. Log detailed technical information.

    2. Return safe user-facing messages.

    3. Avoid exposing credentials or internal infrastructure.

    4. Track recurring failures.

    5. Monitor external service availability.

Best Practices

When handling errors in Ragfish applications:

    1. Validate configuration during startup.

    2. Validate user input before processing.

    3. Handle external provider failures explicitly.

    4. Separate retrieval failures from LLM failures.

    5. Log useful diagnostic information.

    6. Never expose API keys or sensitive information.

    7. Retry only errors that are likely to be temporary.

    8. Use safe user-facing error messages.

    9. Monitor recurring production failures.

Core Framework Complete

You have now completed the core concepts of the Ragfish Framework:

Overview
   ↓
Architecture
   ↓
Settings
   ↓
Assistant
   ↓
Chat
   ↓
Ingestion
   ↓
Chunking
   ↓
Retrieval
   ↓
Interfaces
   ↓
Types
   ↓
Error Handling


You now have the foundation required to understand how Ragfish applications are structured and how the major framework components work together.

What's Next?

The next section of the documentation focuses on AI Providers.

Continue to AI Providers → Overview to learn how Ragfish integrates language models and embedding providers through its modular provider architecture.