Vector DB integration lab
Define the tenant pgvector index input contract
Page 2 hardens the boundary around the tenant-filtered pgvector FAQ index so bad inputs fail before the interesting algorithm runs.
1Learn the idea
Read
Define what may enter
The accepted input remains: chunk rows with tenant_id, embedding, and index_version. Keep parsing and normalization in functions that do not score, train, or call a model. That split lets a test fail the boundary without blaming the core logic. The user-facing decision stays: replace an in-memory list with a versioned vector index that cannot leak across tenants.
Read
Reject at the boundary
row={'tenant_id':'cafe-a','chunk_id':'hours','embedding':[0.1,0.2],'index_version':'v3'}
assert {'tenant_id','chunk_id','embedding','index_version'}<=set(row)
print('chunk contract ok')
Expected evidence: chunk contract ok. If the contract is silent on a bad value, later debugging will look like an algorithm bug when it is really a data bug.
Read
Keep transforms testable
Write one assertion for a neighboring valid input to the tenant pgvector index so tightening the boundary does not over-reject. Document field names and types the way a teammate would need them on day two of vector-db-lab—not as comments you plan to delete.
Read
Lab notebook: name the fields
List every field in two tenants with overlapping vocabulary FAQ chunks and mark each as required, optional, or forbidden. Required fields must fail loudly when missing; optional fields need defaults you can quote in a test; forbidden fields (secrets, raw PII, path escapes) must never be accepted silently. This list is the contract for the tenant pgvector index.
Add one sentence about encoding, units, or timezones if relevant to chunk rows with tenant_id, embedding, and index_version. Contracts that ignore units create “correct” programs that still ship wrong decisions when someone tries to replace an in-memory list with a versioned vector index that cannot leak across tenants.
Read
Worked judgment
Write the error string you want for the most likely bad input. Prefer ValueError('threshold out of range')-style messages over generic invalid input. The contract’s job is to make missing tenant filter in SQL, or querying a stale index version silently harder to confuse with a model or algorithm bug later.
Read
Why this stage matters for the tenant pgvector index
At the data contract stage for vector-db-lab, the job is narrower than finishing a product demo. You are creating one progressive evidence piece about two tenants with overlapping vocabulary FAQ chunks that later pages inherit without redefining success. Keep that fixture small enough to inspect by hand, keep outputs copy-pasteable as text, and refuse to narrate this baseline as if it were a production SLA: in-memory cosine search on the same fixtures.
For this page specifically, success looks like malformed inputs rejected with field-named errors while still centering the user decision to replace an in-memory list with a versioned vector index that cannot leak across tenants. If you cannot point to a file, command, or assertion that proves that for the tenant pgvector index, stay on this page instead of advancing.
Glossary: vector database · Glossary: vector index · Cheatsheet: RAG quality
Go deeper
Before you start
Why this matters
Invent one malformed input that the tenant-filtered pgvector FAQ index might accidentally accept. Predict the exception or rejection message. After you run the contract code, compare your prediction with the real failure text.
In the wild
See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.