
factstore
io.github.Victor-EUv0.1.0更新於 Oct 4, 2026
A fact store for AI agents, on Postgres: registered attributes, every write citing its evidence.
概覽
以 Postgres 為基礎的事實儲存,讓助理記錄附帶證據引用的公司系統與文件事實,並可依任一日期查詢。
- 功能
- 透過 stdio 提供 Postgres 事實儲存,暴露 transact、query、stats、register_attribute、search_attributes、excise 等呼叫。事實是已註冊且具型別之屬性的取值,寫入時的交易會標註寫入者與來源文件;內容不會被覆寫,因此可查詢某個日期時儲存所知道的情況。讀取以單一唯讀語句執行,附帶逾時與列數上限,stats 依屬性簽章將實體分組。
- 適用情境
- 當助理需要把發票、郵件、匯出資料或系統紀錄轉成可長期保存、可稽核的事實,而非臨時筆記時使用。適合重視來源與歷史的擷取與編目流程,以及之後需要查詢某一時點已知情況的情境。
- 執行需求
- 以本機程序方式透過 uvx 執行 PyPI 套件 factstore,需要 Postgres 16 或更新版本、Python 3.12 或更新版本以及 uv。初始化需要超級使用者執行 factstore init,然後建立儲存與 actor 憑證。MCP 伺服器從環境變數 FACTSTORE_DSN 讀取憑證;唯有 FACTSTORE_EXCISE_DSN 也持有切除憑證時才會列出 excise 工具。僅支援桌面端。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 factstore,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
factstore
A fact store for AI agents, on Postgres. Agents record what a company's systems and documents say as facts: a value for a registered attribute, in a transaction stamped with who wrote it and the document it came from. Nothing is overwritten, so the store can say what it knew on any date. Agents use it through an MCP server, and scripts through a Python SDK.
It comes with skills, procedures an agent follows: one indexes a company's systems from their exports, and one reads documents and mail into facts. The design says why it is built this way, and the evals what it was tested on. MIT-licensed.
Install
You need Postgres 16 or later, Python 3.12 or later, and uv for uvx.
1. Postgres. Use your own, or start one. factstore init needs a superuser.
2. A store, and a credential for your agent.
3. Connect your agent. In Claude Code, the plugin brings the MCP server and the skills, and asks for the credential:
Any other MCP client runs the server with the credential in its environment:
factstore skills DIR copies the skills into your agent's skills directory, such as .claude/skills. The catalogue and ingestion skills also write in bulk with the SDK, so the agent's shell needs pip install factstore.
4. Ask. "Read the invoices in ./invoices into the store" uses factstore-ingest. "Index our Shopify and QuickBooks exports" uses factstore-catalogue. "What kinds of thing does the store hold?" uses factstore-ontology.
What the release carries
factstore install STORE NAME installs a package by name, with the packages it depends on.
Personal data. The server's rules keep people's names, addresses and phone numbers out of the store: they stay in the documents. A business that wants an attribute to hold them allows it with core/personal.
Develop
The tests create and drop a store per test. From a source checkout, factstore install also takes a package's directory, such as ../packages/ecom-ops. packages/ describes the package format and the packages. A new version of a package registers what it adds. It may also make an attribute many or identity, the two changes the kernel allows. factstore-skills/ holds the skills.
With FACTSTORE_DSN set, the same calls work at module level: factstore.transact([...]), factstore.query(...).
The MCP server
factstore mcp, or factstore-mcp, serves the calls as tools over stdio. The credential comes from its environment (FACTSTORE_DSN), never from a tool call. excise is listed only when FACTSTORE_EXCISE_DSN holds an excision credential as well. The tool descriptions in tools.py are the documentation models read.
Layout
How the invariants are enforced
Postgres enforces them, not just the Python code:
- Immutability. Writers have
INSERTandSELECTon thefacttable, and nothing else. Triggers refuseUPDATE,TRUNCATE, and anyDELETEoutsidefs_excise(), even from the owner. - The kernel says who wrote. A credential is a Postgres login. A trigger sets each transaction's actor from
session_userand its time from the clock, overwriting anything the client sends. Only the kernel's own functions can writefs/actor,fs/atandfs/excised_*facts. - Registered, typed attributes. Every fact must name a registered attribute (enforced by a foreign key), and a trigger checks its value has that attribute's type. Another trigger stops attributes changing in the wrong direction (a type change, many to one, removing uniqueness).
- Commit order. Each write takes one advisory lock per store and allocates its transaction ID inside it. The trigger takes the same lock again and refuses an ID that isn't after the latest.
Reading
query takes one SQL statement over views (design open question 1, decided by the spike):
- Every attribute is a view named after it:
"po/status"(e, v, tx)in schemacurrent, andhistory."po/status"(e, v, tx, op)over the whole log. - Registration creates the views with a trigger.
- An as-of read sets
factstore.as_of, which every view honours.
A model writes the SQL, so read.py runs it on a separate connection:
- inside a
READ ONLYtransaction that is always rolled back, which undoes anything the statement changes,SET ROLEincluded; - prepared, so Postgres refuses a second statement;
- with a 10 s timeout and a 1,000-row cap.
Advisory locks survive a rollback, so they are released after every read; a query can never hold the writer lock.
stats groups entities by signature, the exact set of attributes each one carries, and counts refs between signatures. That is co-occurrence in the form the ontology skill needs: a kind of thing is usually one signature, or a few that differ by optional attributes.
Decisions made while building
- Cardinality one is enforced at write time. Asserting a new value writes an explicit retraction of the old one to the log. Current state is then a plain fold over assertions and retractions, whatever an attribute's cardinality was at the time.
- Redundant writes are dropped. Asserting a value the entity already has, or retracting one it doesn't have, is reported as unchanged and not logged. A call that changes nothing writes no transaction, so re-running an ingestion leaves the log alone.
- Lookups create only from assertions. A lookup that finds nothing creates the entity when the call asserts something. If the lookup is used only to retract, the call is an error.
- String equality has a hash index. The btree on string values indexes their first 200 characters, so long values never break an insert. Equality goes through a hash index on the whole value, which
v = 'x'on any view can use. - Kernel tests run on bare stores.
initinstalls factstore-core, but the kernel's tests passcore=False: the kernel knows no names, so its tests shouldn't depend on core's. The packages have their own tests. - Near-match thresholds. These are a first calibration on sample attributes, set at the top of
store.py;tests/test_register.pyrecords the cases they were checked against. The "attributes registered" measure in M5 is what tunes them.
來源:factstore/README.md,提交 034f258
工具
0版本歷史
1- v0.1.0最新Oct 4, 2026


