Run This Ai
EN DE

Building a RAG Pipeline with RediSearch Vector Search

A practical tutorial on building RAG pipelines with RediSearch vector search — from Docker setup to hybrid queries combining vector similarity with traditional filters.

RediSearch Logo

Why RediSearch for RAG?

Retrieval-Augmented Generation (RAG) is the backbone of modern AI applications, letting LLMs answer questions based on your private data. RediSearch brings vector search directly into Redis — the database you may already be using for caching and session management. This means no extra infrastructure, no new operational burden, and sub-millisecond latency for your embedding queries.

With RediSearch, you index embeddings using HNSW or FLAT algorithms, run hybrid searches combining vector similarity with traditional filters (tags, dates, geolocation), and retrieve context for your LLM — all from a single Redis instance.

Redis Organization

Setting Up RediSearch

Step 1: Start RediSearch with Docker

docker run -d --name redisearch -p 6379:6379 redislabs/redisearch:latest

Step 2: Create a Vector Index

Connect with redis-cli and create an index for document embeddings:

FT.CREATE doc_idx ON HASH PREFIX 1 doc: SCHEMA\n  title TEXT WEIGHT 2.0\n  content TEXT WEIGHT 1.0\n  source TEXT\n  embedding VECTOR HNSW 6 TYPE FLOAT32 DIM 1536 DISTANCE_METRIC COSINE

Step 3: Index Documents

Store your documents with their embeddings. Using Python with redis-py:

import redis, numpy as np
r = redis.Redis()
embedding = get_embedding("Your document text here")
r.hset("doc:1", mapping={
  "title": "Introduction to RAG",
  "content": "Your document content...",
  "source": "docs/",
  "embedding": np.array(embedding, dtype=np.float32).tobytes()
})

Step 4: Query with Vector Search

Search for semantically similar documents:

query_embedding = get_embedding("What is RAG?")
result = r.ft("doc_idx").search(
  Query("@embedding:[VECTOR_RANGE 0.5 $vec]")
    .return_fields("title","content","source")
    .paging(0, 5)
    .dialect(2),
  query_params={"vec": np.array(query_embedding, dtype=np.float32).tobytes()}
)
RediSearch Logo

Hybrid Search: Vector + Filters

One of RediSearch's superpowers is hybrid search — combine vector similarity with traditional filters in a single query:

FT.SEARCH doc_idx "@embedding:[VECTOR_RANGE 0.5 $vec] @source:{docs/}"\n  PARAMS 2 vec $BLOB\n  DIALECT 2\n  LIMIT 0 10

This retrieves the top 10 documents from the "docs/" source that are semantically similar to your query — perfect for filtering by date, category, or access permissions.

Performance at Scale

RediSearch benchmarks show sub-10ms query times on millions of vectors with HNSW indexes. Combined with Redis's in-memory architecture, it outperforms many standalone vector databases for workloads under 100M vectors while keeping operational complexity near zero.

Conclusion

RediSearch is an ideal vector store for RAG pipelines. It eliminates the need for a separate vector database, reduces latency, and integrates with your existing Redis infrastructure. If you're building AI applications with RAG, give RediSearch a try — you might find you already have everything you need.

#redisearch #rag #vector-search #redis #llm