Run This Ai
EN DE

Getting Started with Typesense: Docker Setup, API Basics, and First Search

Step-by-step tutorial for setting up Typesense with Docker, creating collections, indexing documents, and running typo-tolerant and vector searches for RAG.

Typesense Logo

Introduction

In this tutorial, we will walk through setting up Typesense using Docker, creating your first collection, indexing documents, and running search queries against the REST API. By the end of this guide, you will have a fully functional search engine running locally that you can incorporate into your AI applications and RAG pipelines.

Prerequisites

  • Docker installed on your machine
  • A terminal or command prompt
  • curl or any HTTP client (Postman, Insomnia)

Step 1: Start Typesense with Docker

Typesense runs as a single Docker container with minimal configuration. Create a data directory and start the server:

mkdir -p ./typesense-data

docker run -d --name typesense \\
  -p 8108:8108 \\
  -v $(pwd)/typesense-data:/data \\
  typesense/typesense:latest \\
  --api-key=xyz123 --data-dir=/data

Verify it is running:

curl http://localhost:8108/health
Typesense GitHub

Step 2: Create a Collection

Define the schema for your documents:

curl -X POST http://localhost:8108/collections \\
  -H "X-TYPESENSE-API-KEY: xyz123" \\
  -H "Content-Type: application/json" \\
  -d '{"name": "books", "fields": [
    {"name": "title", "type": "string"},
    {"name": "authors", "type": "string[]"},
    {"name": "description", "type": "string"},
    {"name": "ratings_count", "type": "int32"}
  ], "default_sorting_field": "ratings_count"}'

Step 3: Index Documents

Typesense accepts JSON arrays for bulk indexing:

curl -X POST http://localhost:8108/collections/books/documents/import \\
  -H "X-TYPESENSE-API-KEY: xyz123" \\
  -H "Content-Type: text/plain" \\
  -d '{"title": "The Great Gatsby", "authors": ["F. Scott Fitzgerald"], "description": "A story of wealth and love in the Jazz Age", "ratings_count": 5000}
{"title": "Dune", "authors": ["Frank Herbert"], "description": "Epic science fiction set on a desert planet", "ratings_count": 12000}'

Step 4: Typo-Tolerant Search

Search with automatic typo correction:

curl "http://localhost:8108/collections/books/documents/search?q=gatsby&query_by=title" \\
  -H "X-TYPESENSE-API-KEY: xyz123"

# Even with a typo:
curl "http://localhost:8108/collections/books/documents/search?q=gatzby&query_by=title" \\
  -H "X-TYPESENSE-API-KEY: xyz123"

Both return "The Great Gatsby" — Typesense handles typos automatically.

Step 5: Vector Search for RAG

Typesense supports vector search for AI applications. Store embeddings in a vector field and perform nearest-neighbor search. Use it as your vector store in RAG pipelines:

import requests

response = requests.get(
    "http://localhost:8108/collections/books/documents/search",
    params={"q": prompt, "query_by": "description"},
    headers={"X-TYPESENSE-API-KEY": "xyz123"}
)
context = response.json()["hits"]
# Now send context + prompt to your LLM

Integrating with AI Applications

Typesense fits naturally into RAG architectures. Use it as your vector store to retrieve relevant context before sending queries to an LLM. With its simple REST API, any application can integrate Typesense in minutes. The server runs on just 512MB RAM, making it ideal for edge and self-hosted deployments.

Conclusion

In under five minutes, you have a production-grade search engine with typo correction, faceted search, and vector search capabilities. For your next project that needs fast, relevant search, give Typesense a try.

#typesense #tutorial #docker #search #vector-search #getting-started