Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问许可证需确认审计异常

pgvector-ragpgvector RAG 搜索

Agent Skill

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

总安装

306

周安装

13

GitHub Stars

公开资料未说明

下载量

107
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

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

简介

用于搭建或维护带检索增强的 RAG 工作流。pgvector-rag 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

  • 适合处理知识库问答、向量检索、来源引用和事实核查。
  • 可辅助整理数据接入、Embedding、向量库、召回参数和回答生成流程。
  • 使用时需确认数据来源、更新频率、召回阈值和引用展示方式。
  • 避免把未命中或过期内容包装成确定事实,确保信息准确性。

SKILL.md

pgvector & RAG

Complete toolkit for building vector search and RAG (Retrieval-Augmented Generation) applications with PostgreSQL. Covers pgvector schema setup, embedding generation with Ollama, similarity search, full RAG pipelines, and agentic-kit integration.

When to Apply

Use this skill when:

  • Setting up pgvector: Creating tables, indexes, vector storage schema
  • Generating embeddings: Using Ollama to embed documents and chunks
  • Similarity search: Querying vectors with cosine/L2/inner product distance
  • Building RAG: Combining retrieval with LLM generation
  • Ollama integration: Local LLM inference, model management, streaming
  • Agentic-kit RAG: Wiring RAG into agentic-kit chat applications

Architecture

Document → Chunking → Embedding → pgvector Storage
                                        ↓
Query → Embedding → Similarity Search → Context Retrieval → LLM Response

Quick Start

# 1. Start PostgreSQL with pgvector
pgpm docker start
eval "$(pgpm env)"

# 2. Pull Ollama models
ollama pull nomic-embed-text
ollama pull llama3.2

# 3. Create vector storage module
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

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

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);

Similarity Search Function

CREATE FUNCTION intelligence.find_similar_chunks(
    p_embedding VECTOR(768),
    p_limit INTEGER DEFAULT 5,
    p_similarity_threshold FLOAT DEFAULT 0.7
)
RETURNS TABLE (
    id INTEGER,
    content TEXT,
    similarity FLOAT
) AS $$
BEGIN
    RETURN QUERY
    SELECT
        c.id,
        c.content,
        1 - (c.embedding <=> p_embedding) AS similarity
    FROM intelligence.chunks c
    WHERE c.embedding IS NOT NULL
      AND 1 - (c.embedding <=> p_embedding) > p_similarity_threshold
    ORDER BY c.embedding <=> p_embedding
    LIMIT p_limit;
END;
$$ LANGUAGE plpgsql;

Embedding Models

ModelDimensionsSpeedQuality
nomic-embed-text768FastGood
mxbai-embed-large1024MediumBetter
all-minilm384Very FastAcceptable

Distance Operators

OperatorTypeUse Case
<=>CosineMost common, normalized vectors
<->Euclidean (L2)When magnitude matters
<#>Inner productDot product similarity

TypeScript: OllamaClient

import fetch from 'cross-fetch';

export class OllamaClient {
  private baseUrl: string;

  constructor(baseUrl?: string) {
    this.baseUrl = baseUrl || process.env.OLLAMA_HOST || 'http://localhost:11434';
  }

  async generateEmbedding(text: string, model = 'nomic-embed-text'): Promise<number[]> {
    const response = await fetch(`${this.baseUrl}/api/embeddings`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ model, prompt: text }),
    });
    if (!response.ok) throw new Error(`Embedding failed: ${response.statusText}`);
    const data = await response.json();
    return data.embedding;
  }

  async generateResponse(prompt: string, context?: string, model = 'mistral'): Promise<string> {
    const fullPrompt = context
      ? `Context: ${context}\n\nQuestion: ${prompt}\n\nAnswer:`
      : prompt;
    const response = await fetch(`${this.baseUrl}/api/generate`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ model, prompt: fullPrompt, stream: false }),
    });
    if (!response.ok) throw new Error(`Generation failed: ${response.statusText}`);
    const data = await response.json();
    return data.response;
  }
}

Vector Format

pgvector expects bracket notation:

const formatVector = (embedding: number[]): string => `[${embedding.join(',')}]`;

RAG Query Pattern

// 1. Embed the question
const queryEmbedding = await ollama.generateEmbedding(question);

// 2. Retrieve context
const result = await pool.query(
  `SELECT string_agg(content, E'\n\n') as context
   FROM intelligence.find_similar_chunks($1::vector, $2)`,
  [formatVector(queryEmbedding), 5]
);

// 3. Generate response with context
const response = await ollama.generateResponse(question, result.rows[0].context);

Indexes for Performance

-- IVFFlat (good balance, add after initial data load)
CREATE INDEX idx_chunks_embedding ON intelligence.chunks
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);

-- HNSW (better recall, more memory)
CREATE INDEX idx_chunks_embedding_hnsw ON intelligence.chunks
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);

Environment Variables

VariableDefaultDescription
OLLAMA_HOSThttp://localhost:11434Ollama server URL
RAG_DATABASE_URL-PostgreSQL connection string
RAG_EMBEDDING_MODELnomic-embed-textEmbedding model
RAG_CHAT_MODELllama3.2Chat model
RAG_SIMILARITY_THRESHOLD0.5Minimum similarity score
RAG_CONTEXT_LIMIT5Max chunks to retrieve

Troubleshooting Quick Reference

IssueQuick Fix
"type vector does not exist"pgvector extension not installed; use pgvector-enabled Docker image
"Connection refused" to OllamaStart Ollama: ollama serve
"Model not found"Pull model: ollama pull <model>
Dimension mismatchEnsure VECTOR(n) matches model output dimensions
No results returnedLower similarity threshold
Slow queriesAdd IVFFlat or HNSW index

Reference Guide

Consult these reference files for detailed documentation on specific topics:

ReferenceTopicConsult When
references/setup.mdpgvector schema setupCreating tables, indexes, vector dimensions, pgpm module structure
references/embeddings.mdGenerating and storing embeddingsOllamaClient, document chunking, ingestion pipeline, batch processing
references/similarity-search.mdSimilarity search queriesDistance operators, thresholds, metadata filtering, performance tuning
references/rag-pipeline.mdComplete RAG pipelineRAGService implementation, streaming, chat history, prompt engineering
references/ollama.mdOllama integrationInstallation, API endpoints, model selection, chat API, CI/CD setup
references/agentic-kit.mdAgentic-kit RAGRAGProvider, createRAGKit, useAgent hook, environment config, database schema

Cross-References

Related skills (separate from this skill):

  • graphile-pgvector — Integrate pgvector with PostGraphile v5 GraphQL
  • pgpm (references/docker.md) — PostgreSQL container management for pgvector
  • github-workflows-ollama — GitHub Actions for Ollama and pgvector testing

适合场景

01

研究助手

02

事实核查

03

知识库问答

04

带来源的搜索总结

能力概览

能力 1

组合搜索和大模型调用

能力 2

支持多来源检索和总结

能力 3

强调引用来源和事实核查

能力 4

适合研究型 Agent 流程

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

平台分布

Codex

33.87%
按下载量换算36

Claude

28.87%
按下载量换算31

Cursor

19.04%
按下载量换算20

Gemini CLI

10.07%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

未通过

Snyk

可疑

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

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

来源信息

继续浏览同类 Skills