Repository navigation
pgvector: read tenants from json metadata; never drop a filter - #17
Merged
Merged
Conversation
LangChain (cmetadata) and LlamaIndex (metadata_) keep the tenant in a json or jsonb column, so the isolation probe saw no tenant field and reported a table several tenants share as single-tenant. A json metadata column holding an object is now flattened into its top-level keys (a key colliding with a column is kept as <column>.<key>), and query(where=) filters such a key with @> (GIN-indexable) plus -> equality (exact, typed). query(where=) used to ignore a key that was not a column, running the query unfiltered; it now raises UnsupportedCapability instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
LangChain (
cmetadatajsonb) and LlamaIndex (metadata_json) keep the tenant inside a json column. The isolation probe reported such tables as single-tenant / not applicable while several tenants shared them.<col>.<key>.query(where=)filters inside the column with@>(GIN-indexable) plus->equality, so the match is exact and typed. Acol.keyprefix picks the column explicitly.query(where=)used to silently drop a key that wasn't a column, so a tenant-scoped query ran unfiltered. It now raisesUnsupportedCapability(see the checklist).json_metadata_columns.docs/pgvector.md: new section "Metadata in json columns".How you verified it
ruff check .: cleanpytest -rswithVECSHIELD_PG_DSNpointing at PostgreSQL 17.12 / pgvector 0.8.7, so the live tests ran instead of skipping. Acrosstests/test_pgvector.py,test_pgvector_unit.py,test_pg_access_hardening.py,test_store_facts_selfhosted.pyandtest_isolation.py: 277 passed, 0 skipped.mainshows on this machine (symlinks,/proc, webhook sockets,test_demo). No new failures.npm test: console unchangedhalfvec, and a least-privilege control.Tests added:
tenant_id, andprobe_isolationsees 2 tenants.This is one of six independent pgvector PRs, all based on
main(0041576). They merge cleanly with each other in any order.Checklist
query(where=)now raisesUnsupportedCapabilityinstead of ignoring a key that is neither a column nor inside a json metadata column. This includes filters passed through the runtime proxy, which now fail closed instead of returning unfiltered results.