rag-builder
Build Retrieval-Augmented Generation systems with vector databases
What this skill does
# RAG Builder Skill
> Build the RAG (Retrieval-Augmented Generation) server using Qdrant.
## Overview
The RAG server provides vector search capabilities for the workspace:
- Document ingestion with chunking
- Semantic search across collections
- Multi-project isolation via collections
## Prerequisites
```bash
pip install qdrant-client sentence-transformers mcp fastembed
```
## Using the MCP Server
The Reflex plugin includes a pre-configured Qdrant MCP server. Use these tools:
### Store Documents
```
Tool: qdrant-store
Information: "Your document text here..."
Metadata:
source: "user_upload"
type: "notes"
```
### Search Documents
```
Tool: qdrant-find
Query: "quantum computing applications"
```
## Build Steps (Custom Server)
### Step 1: Create the RAG Server
**File: `mcp/servers/rag-server/server.py`**
```python
#!/usr/bin/env python3
"""
RAG MCP Server - Vector search using Qdrant.
"""
import asyncio
import json
import os
from datetime import datetime
from typing import Optional
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct
from mcp.server import Server
from mcp.server.stdio import stdio_server
from sentence_transformers import SentenceTransformer
# Configuration
QDRANT_URL = os.getenv("QDRANT_URL", "http://localhost:6333")
EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "all-MiniLM-L6-v2")
DEFAULT_COLLECTION = os.getenv("COLLECTION_NAME", "default_memories")
CHUNK_SIZE = int(os.getenv("CHUNK_SIZE", "512"))
CHUNK_OVERLAP = int(os.getenv("CHUNK_OVERLAP", "50"))
class RAGServer:
def __init__(self):
self.server = Server("rag-server")
# Initialize Qdrant
self.client = QdrantClient(url=QDRANT_URL)
# Initialize embedding model
self.embedder = SentenceTransformer(EMBEDDING_MODEL)
self.vector_size = self.embedder.get_sentence_embedding_dimension()
self._setup_tools()
def _ensure_collection(self, name: str):
"""Ensure collection exists."""
collections = self.client.get_collections().collections
if not any(c.name == name for c in collections):
self.client.create_collection(
collection_name=name,
vectors_config=VectorParams(
size=self.vector_size,
distance=Distance.COSINE
)
)
def _chunk_text(self, text: str) -> list[str]:
"""Split text into overlapping chunks."""
words = text.split()
chunks = []
for i in range(0, len(words), CHUNK_SIZE - CHUNK_OVERLAP):
chunk = " ".join(words[i:i + CHUNK_SIZE])
if chunk:
chunks.append(chunk)
return chunks
def _setup_tools(self):
@self.server.tool()
async def ingest(
content: str,
collection: str = DEFAULT_COLLECTION,
metadata: Optional[dict] = None,
doc_id: Optional[str] = None
) -> str:
"""
Ingest a document into the vector database.
Args:
content: Document text to ingest
collection: Collection name (use project name for isolation)
metadata: Optional metadata (source, type, date, etc.)
doc_id: Optional custom document ID
"""
self._ensure_collection(collection)
chunks = self._chunk_text(content)
base_id = doc_id or f"doc_{datetime.now().timestamp()}"
# Generate embeddings
embeddings = self.embedder.encode(chunks).tolist()
# Prepare metadata
base_meta = metadata or {}
base_meta["ingested_at"] = datetime.now().isoformat()
base_meta["source_doc"] = base_id
# Create points
points = [
PointStruct(
id=hash(f"{base_id}_chunk_{i}") % (2**63),
vector=embeddings[i],
payload={**base_meta, "chunk_index": i, "content": chunk}
)
for i, chunk in enumerate(chunks)
]
self.client.upsert(collection_name=collection, points=points)
return json.dumps({
"status": "success",
"collection": collection,
"chunks": len(chunks),
"doc_id": base_id
})
@self.server.tool()
async def search(
query: str,
collection: str = DEFAULT_COLLECTION,
n_results: int = 5
) -> str:
"""
Search for relevant documents.
Args:
query: Search query
collection: Collection to search
n_results: Number of results (default 5)
"""
self._ensure_collection(collection)
query_embedding = self.embedder.encode([query])[0].tolist()
results = self.client.search(
collection_name=collection,
query_vector=query_embedding,
limit=n_results
)
formatted = [
{
"id": str(r.id),
"content": r.payload.get("content", ""),
"metadata": {k: v for k, v in r.payload.items() if k != "content"},
"score": r.score
}
for r in results
]
return json.dumps({
"query": query,
"collection": collection,
"results": formatted
})
@self.server.tool()
async def list_collections() -> str:
"""List all collections."""
collections = self.client.get_collections()
return json.dumps({
"collections": [
{"name": c.name}
for c in collections.collections
]
})
async def run(self):
async with stdio_server() as (read_stream, write_stream):
await self.server.run(read_stream, write_stream)
def main():
server = RAGServer()
asyncio.run(server.run())
if __name__ == "__main__":
main()
```
### Step 2: Create Requirements
**File: `mcp/servers/rag-server/requirements.txt`**
```
mcp>=1.0.0
qdrant-client>=1.7.0
sentence-transformers>=2.2.0
```
### Step 3: Create Test Script
**File: `mcp/servers/rag-server/test_rag.py`**
```python
#!/usr/bin/env python3
"""Quick test for RAG server components."""
import os
import sys
# Set up path
sys.path.insert(0, os.path.dirname(__file__))
def test_qdrant():
"""Test Qdrant is working."""
from qdrant_client import QdrantClient
client = QdrantClient(url="http://localhost:6333")
collections = client.get_collections()
print(f"✅ Qdrant working, {len(collections.collections)} collections")
def test_embeddings():
"""Test embedding model."""
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')
embedding = model.encode(["test sentence"])
assert embedding.shape == (1, 384)
print("✅ Embeddings working")
def test_server_init():
"""Test server initialization."""
from server import RAGServer
server = RAGServer()
assert server.client is not None
assert server.embedder is not None
print("✅ Server initialization working")
if __name__ == "__main__":
test_qdrant()
test_embeddings()
test_server_init()
print("\n✅ All RAG tests passed!")
```
## Verification
```bash
# Start Qdrant (if using Docker)
docker run -d -p 6333:6333 qdrant/qdrant
# Navigate to server directory
cd mcp/servers/rag-server
# Install dependencies
pip install -r requirements.txt
# Run tests
python test_rag.py
# Expected output:
# ✅ Qdrant working, 0 collections
# ✅ Embeddings working
# ✅ Server initialization working
# ✅ All RAG tests passed!
```
## Usage Examples
ORelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.