fastrag.query.chat.schema#

The tables behind PostgresChatStore.

The same columns, the same CHECK constraints, the same message_role / finish_reason / error_code enumerations, the same indexes as the original serving schema — but as a self-managed schema rather than an Alembic-managed ORM Base: PostgresChatStore creates its schema, its three tables, and its three Postgres ENUM types on __aenter__ if they are absent (the same pattern fastrag.ingestion.cache.schema already established for the ingestion cache). It therefore declares its own MetaData rather than attaching to any shared declarative Base — no Alembic, no shared Base, per this task’s own constraints.

Every PostgresChatStore instance calls build_schema() with its own target schema name at construction time (pure Python object construction, no I/O), so the same table shapes can live in as many Postgres schemas as the caller wants — this is what lets the test suite give every test its own isolated schema.

Module Attributes

DEFAULT_SCHEMA

Schema name used when a PostgresChatStore caller does not pick one.

Functions

build_schema([schema])

Build the chat table definitions targeting Postgres schema schema.

Classes

ChatSchema(metadata, sessions, chats, messages)

The three chat tables, bound to one target Postgres schema.

fastrag.query.chat.schema.DEFAULT_SCHEMA = 'fastrag_chat'#

Schema name used when a PostgresChatStore caller does not pick one.

class fastrag.query.chat.schema.ChatSchema(metadata, sessions, chats, messages)[source]#

Bases: object

The three chat tables, bound to one target Postgres schema.

Parameters:
fastrag.query.chat.schema.build_schema(schema='fastrag_chat')[source]#

Build the chat table definitions targeting Postgres schema schema.

Pure metadata construction: no connection is opened and no statement is sent. PostgresChatStore.__aenter__ is what actually creates schema, these tables, and the three ENUM types in the database, if absent.

Parameters:

schema (str)

Return type:

ChatSchema