[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EFTDNMPR0ZD8JFDFSK0DFM":3,"skill-same:01M6EFTDNMPR0ZD8JFDFSK0DFM":45},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":25,"repositoryHtmlUrl":26,"repositoryHomepageUrl":27,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":29,"updatedAt":30,"install":31,"resources":44},"01M6EFTDNMPR0ZD8JFDFSK0DFM","pgvector",null,"ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",66,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FTerminalSkills\u002Fskills\u002Fpgvector\u002FSKILL.md",[],[5],"2026-11-10 10:12:30",false,"# pgvector\n\n## Overview\n\npgvector adds vector similarity search to PostgreSQL. Store embeddings alongside your regular data — no separate vector database, no data sync, no new infrastructure. Use your existing Postgres for semantic search, RAG, recommendations, and deduplication. Supports exact and approximate nearest neighbor search with IVFFlat and HNSW indexes.\n\n## When to Use\n\n- Adding semantic\u002Fvector search to an existing Postgres-backed app\n- RAG (Retrieval-Augmented Generation) without running Pinecone\u002FQdrant\u002FWeaviate\n- Storing embeddings alongside relational data (users, products, documents)\n- Recommendation systems based on content similarity\n- Don't want to manage a separate vector database\n\n## Instructions\n\n### Setup\n\n```sql\n-- Enable the extension (available on Supabase, Neon, RDS, self-hosted)\nCREATE EXTENSION IF NOT EXISTS vector;\n```\n\n### Schema Design\n\n```sql\n-- Store documents with embeddings alongside regular columns\nCREATE TABLE documents (\n  id BIGSERIAL PRIMARY KEY,\n  title TEXT NOT NULL,\n  content TEXT NOT NULL,\n  metadata JSONB DEFAULT '{}',\n  embedding vector(1536),          -- OpenAI ada-002 dimension\n  created_at TIMESTAMPTZ DEFAULT NOW()\n);\n\n-- HNSW index for fast approximate search (recommended)\nCREATE INDEX ON documents\n  USING hnsw (embedding vector_cosine_ops)\n  WITH (m = 16, ef_construction = 64);\n\n-- Or IVFFlat for lower memory usage\n-- CREATE INDEX ON documents\n--   USING ivfflat (embedding vector_cosine_ops)\n--   WITH (lists = 100);\n```\n\n### Store Embeddings\n\n```typescript\n\u002F\u002F ingest.ts — Generate and store embeddings\nimport { Pool } from \"pg\";\nimport OpenAI from \"openai\";\n\nconst pool = new Pool({ connectionString: process.env.DATABASE_URL });\nconst openai = new OpenAI();\n\nasync function storeDocument(title: string, content: string, metadata: object = {}) {\n  \u002F\u002F Generate embedding\n  const embeddingRes = await openai.embeddings.create({\n    model: \"text-embedding-3-small\",\n    input: content,\n  });\n  const embedding = embeddingRes.data[0].embedding;\n\n  \u002F\u002F Store with embedding (pgvector accepts array format)\n  await pool.query(\n    `INSERT INTO documents (title, content, metadata, embedding)\n     VALUES ($1, $2, $3, $4)`,\n    [title, content, JSON.stringify(metadata), JSON.stringify(embedding)]\n  );\n}\n```\n\n### Similarity Search\n\n```typescript\n\u002F\u002F search.ts — Find similar documents by vector distance\nasync function semanticSearch(query: string, limit = 5, threshold = 0.7) {\n  \u002F\u002F Embed the query\n  const embeddingRes = await openai.embeddings.create({\n    model: \"text-embedding-3-small\",\n    input: query,\n  });\n  const queryEmbedding = embeddingRes.data[0].embedding;\n\n  \u002F\u002F Cosine similarity search\n  const result = await pool.query(\n    `SELECT id, title, content, metadata,\n            1 - (embedding \u003C=> $1::vector) AS similarity\n     FROM documents\n     WHERE 1 - (embedding \u003C=> $1::vector) > $2\n     ORDER BY embedding \u003C=> $1::vector\n     LIMIT $3`,\n    [JSON.stringify(queryEmbedding), threshold, limit]\n  );\n\n  return result.rows;\n  \u002F\u002F [{ id: 1, title: \"...\", content: \"...\", similarity: 0.89 }, ...]\n}\n```\n\n### RAG with pgvector\n\n```typescript\n\u002F\u002F rag.ts — Retrieval-Augmented Generation using pgvector\nasync function ragAnswer(question: string): Promise\u003Cstring> {\n  \u002F\u002F 1. Find relevant documents\n  const docs = await semanticSearch(question, 5);\n\n  \u002F\u002F 2. Build context from retrieved documents\n  const context = docs.map((d) => `## ${d.title}\\n${d.content}`).join(\"\\n\\n\");\n\n  \u002F\u002F 3. Generate answer with context\n  const completion = await openai.chat.completions.create({\n    model: \"gpt-4o\",\n    messages: [\n      {\n        role: \"system\",\n        content: `Answer based on the following context. If the context doesn't contain the answer, say so.\\n\\n${context}`,\n      },\n      { role: \"user\", content: question },\n    ],\n  });\n\n  return completion.choices[0].message.content!;\n}\n```\n\n### With Drizzle ORM\n\n```typescript\n\u002F\u002F schema.ts — pgvector with Drizzle ORM\nimport { pgTable, text, serial, jsonb, index, timestamp } from \"drizzle-orm\u002Fpg-core\";\nimport { customType } from \"drizzle-orm\u002Fpg-core\";\n\n\u002F\u002F Custom vector type for Drizzle\nconst vector = customType\u003C{ data: number[]; driverData: string }>({\n  dataType: () => \"vector(1536)\",\n  toDriver: (value) => JSON.stringify(value),\n});\n\nexport const documents = pgTable(\"documents\", {\n  id: serial(\"id\").primaryKey(),\n  title: text(\"title\").notNull(),\n  content: text(\"content\").notNull(),\n  embedding: vector(\"embedding\"),\n  createdAt: timestamp(\"created_at\").defaultNow(),\n});\n```\n\n## Examples\n\n### Example 1: Add semantic search to an existing app\n\n**User prompt:** \"I have a Postgres database with articles. Add semantic search so users can search by meaning, not just keywords.\"\n\nThe agent will add a vector column, generate embeddings for existing articles, create an HNSW index, and build a search endpoint that combines vector similarity with existing filters.\n\n### Example 2: Document Q&A with RAG\n\n**User prompt:** \"Build a Q&A system over our internal docs using our existing Postgres database.\"\n\nThe agent will chunk documents, store embeddings in pgvector, and build a RAG pipeline that retrieves relevant chunks and generates answers.\n\n## Guidelines\n\n- **HNSW index for most cases** — faster queries, slightly more memory than IVFFlat\n- **Cosine distance (`\u003C=>`)** — best for normalized embeddings (OpenAI, Cohere)\n- **L2 distance (`\u003C->`)** — for non-normalized embeddings\n- **Dimension must match model** — ada-002: 1536, text-embedding-3-small: 1536\n- **Index after bulk insert** — create index after loading data, not before\n- **Filter + vector search** — combine `WHERE` clauses with vector similarity\n- **No separate infrastructure** — one less service to manage, deploy, and pay for\n- **Supabase has it built-in** — `enable_extension('vector')` in dashboard\n- **Chunk long documents** — 500-1500 tokens per chunk for best retrieval\n- **Re-embed when you change models** — embeddings from different models aren't compatible\n",{},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002FTerminalSkills\u002Fskills\u002Fpgvector",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":7,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill pgvector",{"tool":37,"command":38},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill pgvector",{"tool":40,"command":41},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill pgvector","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FTerminalSkills\u002Fskills\u002Fpgvector\u002FSKILL.md",true,[],[46,60,70,79,85,92],{"skillNo":47,"name":48,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":56,"publishedAt":18},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[51],{"categoryNo":52,"categoryName":53,"taxonomyType":54,"taxonomyTypeDesc":55},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[57,58,59],"model","model hierarchy","model hierarchy skill",{"skillNo":61,"name":62,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":66,"publishedAt":18},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[65],{"categoryNo":52,"categoryName":53,"taxonomyType":54,"taxonomyTypeDesc":55},[67,68,69],"MCP","zoom","zoom mcp",{"skillNo":71,"name":72,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":18},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[76,77,78,68],"sdk","zoom apps sdk","apps",{"skillNo":80,"name":81,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":18},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[81],{"skillNo":86,"name":87,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":91,"publishedAt":18},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[90],{"categoryNo":52,"categoryName":53,"taxonomyType":54,"taxonomyTypeDesc":55},[87],{"skillNo":93,"name":94,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":18},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[94]]