amu-pgvector

io.github.sangaraju1988由 GitHub 账号 sangaraju1988 发布v0.1.3更新于 Oct 28, 2026

Lineage-gated agent memory tools on Postgres + pgvector, enforced by row-level security.

概览

AI 生成的概览

基于 Postgres + pgvector 的谱系门控智能体记忆:存储缓存结果,只向有权查看其来源列的数据库角色返回结果。

可以做什么
  • 按语义检索已存储的记忆单元,结果按请求角色的权限过滤
  • 记录缓存结果及其生成所用的 SQL,从而捕获其数据谱系
  • 在复用或新增结果前检查指标定义是否冲突
  • 所有读写都经过 Postgres 行级安全策略,原生 SQL、Python 客户端、LangChain 与本服务器共用同一道门控
适用场景
适合多个智能体或部门共享缓存结果记忆、且需要防止某团队的派生数值泄露给无权查看底层列的团队时使用。也适合需要对指标定义做冲突检测的场景。
运行要求
以 uvx 从 PyPI 包(含 mcp 附加项)在本地运行的进程。需要一个装有 pgvector 扩展并已导入项目 SQL 架构的 PostgreSQL 数据库,以及通过 AMU_PGVECTOR_DSN 提供的、供服务器所用角色连接的 Postgres DSN;该角色需为 amu_writer 成员才能记录或检查冲突。使用内置回退嵌入器时,AMU_PGVECTOR_EMBEDDING_DIM 必须与架构中的向量维度一致。
安装前请注意
DSN 是数据库凭据,服务器权限即该角色的权限,应使用专用的最小权限角色而非属主或超级用户账号。记录与冲突检查会写入数据库。设计上信任写入方提供的谱系信息,因此谎报谱系的写入方不在防护范围内,超级用户也会绕过行级安全。README 中的默认属主密码仅限本地开发使用。

安装

在 SourceWeft 中

  1. 打开 控制台中的 amu-pgvector,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

amu-pgvector

[DOI]

Reference implementation of Lineage-Aware Memory Governance (Sangaraju & Vissa, IEEE Access, 10.1109/ACCESS.2026.3730363) on PostgreSQL + pgvector.

The problem

Say Finance computes avg(income) for a customer segment and caches the result so the next agent that asks the same question doesn't have to recompute it. Later, a Marketing agent asks a semantically similar question -- "what's the average customer income by segment?" -- and a naive shared memory, gated only on the metric's name or content tags, serves back Finance's cached result. Marketing was never permitted to see income. The result itself doesn't look like income -- it's a number -- but it was derived from a column Marketing isn't permitted to touch, and nothing about matching on metric name or content catches that. That's the leak this project closes: gating reuse on how a result was derived, not on what it looks like.

60-second quickstart

bash
git clone https://github.com/sangaraju1988/amu-pgvector.gitcd amu-pgvectordocker compose up -dpsql -h localhost -p 5433 -U amu_owner -d amu_dev -f sql/amu_pgvector.sql# password: amu_owner_password
bash
uv sync --all-packages --all-extras   # or: pip install amu-pgvector
python
from amu_pgvector import AMUStorefrom amu_pgvector.embeddings import fake_embedder
DSN = "postgresql://amu_owner:amu_owner_password@localhost:5433/amu_dev"embed = fake_embedder(dim=1536)  # swap for a real embedding model in production
admin = AMUStore(DSN)admin.register_sensitive_column("income")admin.grant_department_permission("Finance", "income")admin.create_agent_role("finance_agent", "Finance", "finance_pw")admin.create_agent_role("marketing_agent", "Marketing", "marketing_pw")
admin.record(    "SELECT avg(income) FROM customers",    {"avg": 82000},    metric_name="avg_income",    description="average customer income",    owner_department="Finance",    embed_fn=embed,)
finance_dsn = "postgresql://finance_agent:finance_pw@localhost:5433/amu_dev"marketing_dsn = "postgresql://marketing_agent:marketing_pw@localhost:5433/amu_dev"
AMUStore(finance_dsn).search("average customer income", k=5, embed_fn=embed)# -> [SearchResult(metric_name='avg_income', ...)]
AMUStore(marketing_dsn).search("average customer income", k=5, embed_fn=embed)# -> [] -- Marketing was never granted `income`, so Postgres itself#          never returns the row, regardless of how the query is asked.

Every line above was run against this exact repo before being written here (see docs/design.md for what a from-scratch install actually looks like). amu_owner/amu_owner_password is the docker-compose default -- change it for anything beyond local development.

How the gate works

amu.memory_units is a normal Postgres table with FORCE ROW LEVEL SECURITY enabled. Every write goes through a trigger that extracts the lineage of the SQL that actually produced the cached result (via amu-governance's sql_lineage module -- not self-reported by the agent), closes it over any registered materialized-view/derived-table edges, and computes S(a): the set of sensitive columns that lineage actually touches. A SELECT policy enforces S(a) ⊆ P(d) -- the row is visible only if every column in S(a) is in the requesting role's permitted set P(d) -- for every query against the table, from every client: raw SQL, amu.search(), the Python client, the LangChain integration, and the MCP server all go through the same policy, because it's the table's policy, not any one client's filter.

mermaid
sequenceDiagram    participant Writer as amu_writer role<br/>(trusted interception layer)    participant PG as Postgres: amu.memory_units<br/>(FORCE ROW LEVEL SECURITY)    participant Trigger as BEFORE INSERT trigger    participant Finance as finance_agent role    participant Marketing as marketing_agent role
    Writer->>PG: INSERT ... lineage = {"steps":[{"table":"customers","columns_used":["income"]}]}    PG->>Trigger: compute lineage_columns, S(a), lineage_status    Trigger-->>PG: sensitive_columns = {income}, resolved
    Finance->>PG: SELECT ... (session_user = finance_agent)    PG->>PG: S(a)={income} subset P(Finance)={income,...}? yes    PG-->>Finance: row returned
    Marketing->>PG: SELECT ... (session_user = marketing_agent)    PG->>PG: S(a)={income} subset P(Marketing)={...}? no    PG-->>Marketing: row not returned

See docs/design.md for how every paper concept maps to a specific SQL object, and docs/sql-reference.md for an exhaustive reference of every table, function, role and policy.

Security model and limits

Protected: cross-department leakage of a cached result's derivation columns (the core guarantee, enforced by RLS); silent metric-definition conflicts (amu.check_conflict()); a column reclassified as sensitive after AMUs already exist (a trigger recomputes affected rows, no rewrite needed); lineage closure that silently truncates a long or cyclic derivation chain (fails closed -- marks the AMU unresolved and invisible, rather than serving a partially-traced result).

Explicitly out of scope: a writer that lies about lineage (the SQL gate trusts amu_writer's input by design); inference by combining several individually-permitted AMUs; Postgres superusers, who always bypass RLS; timing side channels; a "convenience mode" identity option (off by default) that's only as safe as the boundary between trusted application code and agent-influenced code on a pooled connection.

Full writeup: docs/threat-model.md.

Benchmarks

Every number below is quoted directly from results/SUMMARY.md, generated by benchmarks/generate_summary.py from committed results/<name>/<timestamp>/ runs (git SHA, Postgres/pgvector versions, hardware, seed and parameters in each run's manifest.json). Re-run the benchmark scripts yourself to reproduce or challenge these; nothing here is estimated.

Leak rate (2000 requests over 600 synthetic AMUs, Finance/Marketing/Support):

ConditionServedCross-department leaksLeak rate
Naive (content-gated, no lineage check)2000101050.5%
amu-pgvector (RLS-gated)99000.0%

Latency (p50/p95 at k=10; RLS and hnsw.iterative_scan each on/off, same role/queries/data per row):

nRLSiterative_scanp50 (ms)p95 (ms)
10,000onon (amu.search() default)66.870.2
10,000onoff81.988.2
10,000offon19.521.8
10,000offoff49.252.3
100,000onon (amu.search() default)712.9851.2
100,000onoff43.465.7
100,000offon376.8418.5
100,000offoff46.670.9

Read honestly: hnsw.iterative_scan=relaxed_order (what amu.search() uses by default, so that filtered results still hit k even when most rows are hidden) costs real latency at scale -- roughly 16x slower than iterative-off at 100k rows in this run. That's the price of the recall guarantee below; if your visible fraction is consistently high, you may prefer to query without it. 1M-row scale was not attempted: the 100k HNSW index build alone took about 7 minutes on the machine this was run on (Docker Desktop on macOS, sharing the host with unrelated workloads) -- recorded honestly rather than extrapolated.

Filtered recall (recall@10 of gated HNSW search vs. exact brute-force over the same role's actually-visible rows, n=20,000):

Visible fractionrecall@10 (mean)recall@10 (min)
50%100.0%100.0%
10%100.0%100.0%
1%100.0%100.0%

Integrations

  • Plain SQL -- sql/amu_pgvector.sql is the artifact that matters most: idempotent, installs on a managed Postgres as a normal database owner (no superuser), no C extensions beyond vector. Works identically on Supabase and Neon (see submissions/supabase-neon-guide.md for a from-scratch tutorial covering both).
  • LangChain -- langchain-amu provides AMUVectorStore and AMURetriever. Every read runs under the store's own Postgres role, so RLS gates LangChain the same way it gates raw SQL. See packages/langchain-amu/.
  • MCP -- pip install amu-pgvector[mcp] adds an amu-pgvector-mcp console script exposing amu_search, amu_record and amu_check_conflict as tools, gated the same way. See packages/amu-pgvector/src/amu_pgvector/mcp_server.py.

Citation

bibtex
@article{sangaraju2026lineage,  title   = {Lineage-Aware Memory Governance: A Derivation-Gated Framework             for Privacy-Preserving Column-Level Access Control in             Enterprise AI Agents},  author  = {Sangaraju, Venkata and Vissa, Sudhir},  journal = {IEEE Access},  year    = {2026},  doi     = {10.1109/ACCESS.2026.3730363}}

See CITATION.cff to also cite this software directly.

License

MIT. See LICENSE.

Related

来源:README.md,提交 ad181f7

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v0.1.3最新Oct 1, 2026
  2. v0.1.2Sep 29, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分