---
title: "Building RAG Applications with HeliosDB"
description: "A step-by-step guide to building Retrieval-Augmented Generation pipelines using HeliosDB's native vector search and SQL."
date: 2025-11-15
updated: 2025-11-15
tag: "Tutorial"
canonical: https://www.heliosdb.com/blog/building-rag-applications-with-heliosdb.html
---

# Building RAG Applications with HeliosDB

Retrieval-Augmented Generation (RAG) is the most practical way to give LLMs access to your private data. But building a production RAG pipeline typically requires stitching together a vector database, a text search engine, an embedding service, and custom retrieval logic. HeliosDB eliminates this complexity by providing all of these capabilities in a single database.

## The RAG Architecture

A RAG pipeline has four stages: (1) chunk documents, (2) generate embeddings, (3) store and index, (4) retrieve and augment. HeliosDB handles stages 2-4 natively.

```
Traditional RAG Stack:
  App → Chunking → OpenAI API → Pinecone (vectors) + Elasticsearch (text)
                                → Custom fusion logic → LLM

HeliosDB RAG Stack:
  App → Chunking → HeliosDB (vectors + text + hybrid search) → LLM
```

## Step 1: Create Tables

```
-- Document storage with embeddings
CREATE TABLE documents (
    id SERIAL PRIMARY KEY,
    title TEXT NOT NULL,
    content TEXT NOT NULL,
    metadata JSONB,
    embedding VECTOR(768),    -- BERT-sized embeddings
    created_at TIMESTAMP DEFAULT NOW()
);

-- HNSW index for fast vector search
CREATE INDEX ON documents USING hnsw (embedding)
  WITH (m = 16, ef_construction = 200);

-- Full-text index for BM25 keyword search
CREATE INDEX ON documents USING fulltext (content);
```

## Step 2: Ingest Documents

```
-- Insert with pre-computed embedding
INSERT INTO documents (title, content, embedding)
VALUES (
    'HeliosDB Architecture',
    'HeliosDB uses a Rust-based storage engine built on RocksDB...',
    embedding('text-embedding-3-small', 'HeliosDB uses a Rust-based storage engine...')
);

-- Bulk insert from your chunking pipeline
COPY documents (title, content, embedding)
FROM STDIN WITH (FORMAT csv);
```

## Step 3: Semantic Search

```
-- Pure vector search (semantic similarity)
SELECT title, content,
       embedding <=> embedding('text-embedding-3-small', 'How does MVCC work?') AS distance
FROM documents
ORDER BY distance ASC
LIMIT 5;

-- Returns the 5 most semantically similar documents
-- regardless of keyword overlap
```

## Step 4: Hybrid Search (Vector + BM25)

Pure vector search misses exact keyword matches. Pure text search misses semantic similarity. Hybrid search combines both using rank fusion:

```
-- Hybrid search: vector similarity + BM25 keyword relevance
SELECT title, content,
       hybrid_score(
           embedding <=> embedding('text-embedding-3-small', 'MVCC transaction isolation'),
           bm25_score(content, 'MVCC transaction isolation'),
           0.7  -- weight: 70% semantic, 30% keyword
       ) AS relevance
FROM documents
ORDER BY relevance DESC
LIMIT 10;
```

HeliosDB Full provides a dedicated hybrid search engine with multiple fusion strategies:

```
-- Hybrid search with RankFusion (reciprocal rank fusion)
SELECT * FROM hybrid_search(
    table_name => 'documents',
    vector_column => 'embedding',
    text_column => 'content',
    query => 'How does MVCC handle concurrent transactions?',
    fusion => 'rank_fusion',   -- or 'weighted_sum'
    k => 10
);
```

## Step 5: Feed to Your LLM

```
-- Retrieve context, then send to LLM in your application
WITH context AS (
    SELECT content
    FROM documents
    ORDER BY embedding <=> embedding('text-embedding-3-small', $1) ASC
    LIMIT 5
)
SELECT string_agg(content, E'\n---\n') AS rag_context
FROM context;
```

## Advanced: Multimodal RAG

HeliosDB Full supports multimodal embeddings for searching across text, images, audio, and video using CLIP, Wav2Vec, and VideoMAE embeddings. Store all modalities in the same database with unified vector search:

```
-- Multimodal document storage
CREATE TABLE knowledge_base (
    id SERIAL PRIMARY KEY,
    content_type TEXT,          -- 'text', 'image', 'audio', 'video'
    content BYTEA,
    description TEXT,
    embedding VECTOR(512),      -- CLIP embedding (unified space)
    metadata JSONB
);

-- Search across modalities
SELECT * FROM knowledge_base
ORDER BY embedding <=> clip_embedding('a cat sitting on a keyboard')
LIMIT 10;
-- Returns matching text, images, audio, and video
```

## Production Considerations

**Embedding Provider Integration:** HeliosDB supports OpenAI, Cohere, Voyage, Google, and local models (via Ollama with 16K context) for embedding generation.

**Chunking Strategy:** We recommend 512-token chunks with 50-token overlap for general-purpose RAG. For code documentation, use function-level chunking.

**Index Tuning:** For datasets under 1M vectors, use HNSW with default parameters. For larger datasets, enable PQ compression. For billion-scale, use IVF-PQ with GPU acceleration (Full edition).
