Token导航 LogoToken导航TokenDH.com
研究检索只读github未标认证来源可访问许可证需确认审计通过

pgvector-setuppg 向量设置

Agent Skill

用于搭建或维护带检索增强的 RAG 工作流,适合让 Agent 处理知识库问答、向量检索、来源引用和事实核查。它可以辅助整理数据接入、Embedding、向量库、召回参数和回答生成流程。使用时需要确认数据来源、更新频率、召回阈值和引用展示方式,避免把未命中的资料或过期内容包装成确定事实。

总安装

186

周安装

8

GitHub Stars

公开资料未说明

下载量

65
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:pgvector-setup(pg 向量设置)
来源仓库:https://github.com/constructive-io/constructive-skills
仓库路径:skills/pgvector-setup
安装命令:
npx skills add https://github.com/constructive-io/constructive-skills --skill pgvector-setup
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/constructive-io/constructive-skills --skill pgvector-setup

简介

用于在 PostgreSQL 中部署 pgvector 扩展以支持向量嵌入存储与检索。

  • 是构建 RAG(检索增强生成)应用的基础设施前提条件。
  • 适用于语义搜索、文档向量化及知识库问答系统开发。
  • 需确保 PostgreSQL 实例已加载 pgvector,推荐使用指定 Docker 镜像。
  • pgvector-setup 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

pgvector Setup

Set up PostgreSQL with pgvector for storing and querying vector embeddings. This is the foundation for building RAG (Retrieval-Augmented Generation) applications.

When to Apply

Use this skill when:

  • Setting up vector storage for embeddings
  • Creating tables to store document embeddings
  • Building semantic search functionality
  • Implementing RAG pipelines with PostgreSQL
  • Migrating from other vector databases to PostgreSQL

Prerequisites

pgvector must be available in your PostgreSQL instance. Use one of these Docker images:

ImageDescription
pyramation/postgres:17PostgreSQL 17 with pgvector (recommended)
ghcr.io/constructive-io/docker/postgres-plus:17PostgreSQL 17 with pgvector and additional extensions

Quick Start

1. Start PostgreSQL with pgvector

Ensure PostgreSQL is running with a pgvector-enabled image (see pgpm-docker skill) and PG env vars are loaded (see pgpm-env skill).

2. Create Schema and Tables

Create a pgpm module for your vector storage:

pgpm init my-vectors
cd my-vectors
pgpm add schemas/intelligence
pgpm add schemas/intelligence/tables/documents --requires schemas/intelligence
pgpm add schemas/intelligence/tables/chunks --requires schemas/intelligence/tables/documents

Schema Design

Documents Table

Store full documents with their embeddings:

-- deploy/schemas/intelligence/tables/documents.sql
-- Deploy: schemas/intelligence/tables/documents
-- requires: schemas/intelligence

CREATE TABLE intelligence.documents (
    id SERIAL PRIMARY KEY,
    title TEXT,
    content TEXT NOT NULL,
    metadata JSONB DEFAULT '{}'::jsonb,
    embedding VECTOR(768),
    created_at TIMESTAMPTZ DEFAULT NOW()
);

Chunks Table

Store document chunks for granular retrieval:

-- deploy/schemas/intelligence/tables/chunks.sql
-- Deploy: schemas/intelligence/tables/chunks
-- requires: schemas/intelligence/tables/documents

CREATE TABLE intelligence.chunks (
    id SERIAL PRIMARY KEY,
    document_id INTEGER NOT NULL REFERENCES intelligence.documents(id) ON DELETE CASCADE,
    content TEXT NOT NULL,
    embedding VECTOR(768),
    chunk_index INTEGER NOT NULL,
    created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX idx_chunks_document_id ON intelligence.chunks(document_id);

Chat History Table (Optional)

Track conversation history for RAG sessions:

-- deploy/schemas/intelligence/tables/chat_history.sql
CREATE TABLE intelligence.chat_history (
    id SERIAL PRIMARY KEY,
    session_id TEXT NOT NULL,
    role TEXT NOT NULL CHECK (role IN ('user', 'assistant', 'system')),
    content TEXT NOT NULL,
    created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX idx_chat_history_session ON intelligence.chat_history(session_id);

Vector Dimensions

Choose dimensions based on your embedding model:

ModelDimensionsUse Case
nomic-embed-text768General purpose, good balance
all-MiniLM-L6-v2384Lightweight, fast
text-embedding-ada-0021536OpenAI, high quality
text-embedding-3-small1536OpenAI, newer model

Declare the dimension in your VECTOR type:

embedding VECTOR(768)   -- For nomic-embed-text
embedding VECTOR(1536)  -- For OpenAI models

Indexes for Performance

IVFFlat Index (Recommended for Most Cases)

Good balance of speed and accuracy:

-- Create after inserting initial data
CREATE INDEX idx_chunks_embedding ON intelligence.chunks
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);

The lists parameter should be approximately sqrt(num_rows).

HNSW Index (Better Recall)

Higher memory usage but better recall:

CREATE INDEX idx_chunks_embedding_hnsw ON intelligence.chunks
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);

Revert Scripts

Always include revert scripts for pgpm:

-- revert/schemas/intelligence/tables/documents.sql
DROP TABLE IF EXISTS intelligence.documents;

-- revert/schemas/intelligence/tables/chunks.sql
DROP TABLE IF EXISTS intelligence.chunks;

Verify Scripts

Confirm deployment succeeded:

-- verify/schemas/intelligence/tables/documents.sql
DO $$
BEGIN
  PERFORM 1 FROM pg_tables
  WHERE schemaname = 'intelligence' AND tablename = 'documents';
  IF NOT FOUND THEN
    RAISE EXCEPTION 'Table intelligence.documents does not exist';
  END IF;
END $$;

Complete Module Structure

my-vectors/
├── deploy/
│   └── schemas/
│       └── intelligence/
│           ├── schema.sql
│           └── tables/
│               ├── documents.sql
│               ├── chunks.sql
│               └── chat_history.sql
├── revert/
│   └── schemas/
│       └── intelligence/
│           ├── schema.sql
│           └── tables/
│               ├── documents.sql
│               ├── chunks.sql
│               └── chat_history.sql
├── verify/
│   └── schemas/
│       └── intelligence/
│           ├── schema.sql
│           └── tables/
│               ├── documents.sql
│               ├── chunks.sql
│               └── chat_history.sql
├── pgpm.plan
└── package.json

Deploying

pgpm deploy --database myapp_dev --createdb --yes

Troubleshooting

IssueSolution
"type vector does not exist"pgvector extension not installed; use a pgvector-enabled image
"dimension mismatch"Embedding dimension doesn't match VECTOR(n) declaration
Slow queriesAdd IVFFlat or HNSW index after initial data load
Out of memoryReduce HNSW parameters or use IVFFlat instead

References

  • Related skill: pgvector-embeddings for generating and storing embeddings
  • Related skill: pgvector-similarity-search for querying vectors
  • Related skill: rag-pipeline for complete RAG implementation
  • pgvector documentation

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.34%
按下载量换算24

Claude

29.9%
按下载量换算19

Cursor

16.8%
按下载量换算11

Gemini CLI

9.08%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills