vector-db-setup
Sets up vector databases for semantic search including Pinecone, Chroma, pgvector, and Qdrant with embedding generation and similarity search. Use when users request "vector database", "semantic search", "embeddings storage", "Pinecone setup", or "similarity search".
What this skill does
# Vector Database Setup
Configure vector databases for semantic search and AI applications.
## Core Workflow
1. **Choose database**: Select based on requirements
2. **Setup connection**: Configure client
3. **Generate embeddings**: Create vector representations
4. **Index documents**: Store with metadata
5. **Query vectors**: Semantic similarity search
6. **Optimize**: Tune for performance
## Database Comparison
| Database | Type | Best For | Scaling |
|----------|------|----------|---------|
| Pinecone | Managed | Production, no ops | Automatic |
| Chroma | Embedded/Server | Development, local | Manual |
| pgvector | PostgreSQL ext | Existing Postgres | With Postgres |
| Qdrant | Self-hosted | Full control | Manual |
| Weaviate | Managed/Self | GraphQL-like API | Both |
## Embeddings Generation
### OpenAI Embeddings
```typescript
// embeddings/openai.ts
import OpenAI from 'openai';
const openai = new OpenAI();
export async function generateEmbedding(text: string): Promise<number[]> {
const response = await openai.embeddings.create({
model: 'text-embedding-3-small', // or text-embedding-3-large
input: text,
});
return response.data[0].embedding;
}
export async function generateEmbeddings(texts: string[]): Promise<number[][]> {
const response = await openai.embeddings.create({
model: 'text-embedding-3-small',
input: texts,
});
return response.data.map((d) => d.embedding);
}
```
### Batch Processing
```typescript
// embeddings/batch.ts
const BATCH_SIZE = 100;
export async function batchGenerateEmbeddings(
texts: string[]
): Promise<number[][]> {
const embeddings: number[][] = [];
for (let i = 0; i < texts.length; i += BATCH_SIZE) {
const batch = texts.slice(i, i + BATCH_SIZE);
const batchEmbeddings = await generateEmbeddings(batch);
embeddings.push(...batchEmbeddings);
// Rate limiting
if (i + BATCH_SIZE < texts.length) {
await new Promise((resolve) => setTimeout(resolve, 100));
}
}
return embeddings;
}
```
## Pinecone Setup
### Installation & Config
```bash
npm install @pinecone-database/pinecone
```
```typescript
// db/pinecone.ts
import { Pinecone } from '@pinecone-database/pinecone';
const pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY!,
});
// Get or create index
export async function getIndex(indexName: string) {
const indexes = await pinecone.listIndexes();
if (!indexes.indexes?.find((i) => i.name === indexName)) {
await pinecone.createIndex({
name: indexName,
dimension: 1536, // OpenAI embedding dimension
metric: 'cosine',
spec: {
serverless: {
cloud: 'aws',
region: 'us-east-1',
},
},
});
// Wait for index to be ready
await new Promise((resolve) => setTimeout(resolve, 60000));
}
return pinecone.Index(indexName);
}
```
### Upsert & Query
```typescript
// db/pinecone-ops.ts
import { getIndex } from './pinecone';
import { generateEmbedding, generateEmbeddings } from '../embeddings/openai';
const index = await getIndex('my-index');
interface Document {
id: string;
content: string;
metadata: Record<string, any>;
}
// Upsert documents
export async function upsertDocuments(
documents: Document[],
namespace = 'default'
) {
const embeddings = await generateEmbeddings(documents.map((d) => d.content));
const vectors = documents.map((doc, i) => ({
id: doc.id,
values: embeddings[i],
metadata: {
content: doc.content,
...doc.metadata,
},
}));
// Upsert in batches
const BATCH_SIZE = 100;
for (let i = 0; i < vectors.length; i += BATCH_SIZE) {
const batch = vectors.slice(i, i + BATCH_SIZE);
await index.namespace(namespace).upsert(batch);
}
}
// Query similar documents
export async function querySimilar(
query: string,
options: {
topK?: number;
namespace?: string;
filter?: Record<string, any>;
} = {}
) {
const { topK = 5, namespace = 'default', filter } = options;
const queryEmbedding = await generateEmbedding(query);
const results = await index.namespace(namespace).query({
vector: queryEmbedding,
topK,
includeMetadata: true,
filter,
});
return results.matches?.map((match) => ({
id: match.id,
score: match.score,
content: match.metadata?.content,
metadata: match.metadata,
}));
}
// Delete documents
export async function deleteDocuments(ids: string[], namespace = 'default') {
await index.namespace(namespace).deleteMany(ids);
}
// Delete by filter
export async function deleteByFilter(
filter: Record<string, any>,
namespace = 'default'
) {
await index.namespace(namespace).deleteMany({ filter });
}
```
## Chroma Setup
### Installation & Config
```bash
npm install chromadb
```
```typescript
// db/chroma.ts
import { ChromaClient, OpenAIEmbeddingFunction } from 'chromadb';
const client = new ChromaClient({
path: process.env.CHROMA_URL || 'http://localhost:8000',
});
const embedder = new OpenAIEmbeddingFunction({
openai_api_key: process.env.OPENAI_API_KEY!,
openai_model: 'text-embedding-3-small',
});
export async function getCollection(name: string) {
return client.getOrCreateCollection({
name,
embeddingFunction: embedder,
metadata: { 'hnsw:space': 'cosine' },
});
}
```
### Chroma Operations
```typescript
// db/chroma-ops.ts
import { getCollection } from './chroma';
const collection = await getCollection('documents');
// Add documents (Chroma generates embeddings)
export async function addDocuments(documents: Document[]) {
await collection.add({
ids: documents.map((d) => d.id),
documents: documents.map((d) => d.content),
metadatas: documents.map((d) => d.metadata),
});
}
// Query
export async function query(queryText: string, nResults = 5) {
const results = await collection.query({
queryTexts: [queryText],
nResults,
});
return results.ids[0].map((id, i) => ({
id,
content: results.documents?.[0][i],
metadata: results.metadatas?.[0][i],
distance: results.distances?.[0][i],
}));
}
// Query with filter
export async function queryWithFilter(
queryText: string,
filter: Record<string, any>,
nResults = 5
) {
const results = await collection.query({
queryTexts: [queryText],
nResults,
where: filter,
});
return results;
}
// Update document
export async function updateDocument(id: string, content: string, metadata?: Record<string, any>) {
await collection.update({
ids: [id],
documents: [content],
metadatas: metadata ? [metadata] : undefined,
});
}
// Delete
export async function deleteDocuments(ids: string[]) {
await collection.delete({ ids });
}
```
## pgvector Setup
### Installation
```bash
npm install pg pgvector
```
```sql
-- Enable extension
CREATE EXTENSION vector;
-- Create table
CREATE TABLE documents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
content TEXT NOT NULL,
metadata JSONB,
embedding vector(1536),
created_at TIMESTAMP DEFAULT NOW()
);
-- Create index for similarity search
CREATE INDEX ON documents USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);
-- Or use HNSW (better for production)
CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);
```
### pgvector Operations
```typescript
// db/pgvector.ts
import { Pool } from 'pg';
import pgvector from 'pgvector/pg';
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
// Register pgvector type
await pgvector.registerType(pool);
// Insert document
export async function insertDocument(
content: string,
embedding: number[],
metadata?: Record<string, any>
) {
const result = await pool.query(
`INSERT INTO documents (content, embedding, metadata)
VALUES ($1, $2, $3)
RETURNING id`,
[content, pgvector.toSql(embedding), metadata]
);
return result.rows[0].id;
}
// Similarity search
export async function searchSimilar(
queryEmbedding: number[],
limit = 5,Related 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.