Skip to main content

Crate smooth_operator_adapter_postgres

Crate smooth_operator_adapter_postgres 

Source
Expand description

Postgres + pgvector StorageAdapter — the dogfood backend.

This is the production Postgres implementation of the one storage seam (see docs/STORAGE.md). It mirrors the smooai monorepo’s schema so dogfooding is a swap, not a rewrite:

  • OLTP (conversations / participants / messages / sessions): async CRUD over a deadpool_postgres pool, semantics matching the in-memory baseline (conversation idempotency, external-id participant resolve, cursor message paging, session status/counts).
  • Checkpoints: smooth-operator’s PostgresCheckpointStore (a synchronous r2d2-pooled store) constructed against the same database — so the engine’s with_checkpoint_store plugs straight in and agent state lives next to the conversations it belongs to.
  • Knowledge: a pgvector-backed PgKnowledgeBase (dense HNSW cosine ∪ sparse tsvector BM25 → Reciprocal Rank Fusion). Text→vector goes through the Embedder seam — DeterministicEmbedder by default (reproducible, no network), GatewayEmbedder when a live gateway is configured.
  • Memory: a pgvector-backed PgMemory (parity gap Phase 3 / SMOODEV-1470) — persistent, semantic, cross-thread agent memory namespaced by (organization_id, user_id) like the TS ['memories', orgId, userId] store. Implements the core Memory trait; recall is pgvector cosine top-K under an HNSW index, scoped to the namespace. Shares the adapter’s Embedder.

§Sharing one database between the async pool and the sync checkpoint store

The OLTP/knowledge slices need async (tokio-postgres + deadpool); the checkpoint slice is a sync trait backed by an r2d2 pool inside smooth-operator. Both are pointed at the same conn_str: we build the async deadpool from it for our own queries, and hand the same string to PostgresCheckpointStore::connect, which stands up its own small r2d2 pool and checkpoints table in that database. Two pools, two driver stacks, one Postgres — the tables coexist (ours from [schema], theirs from their own CREATE TABLE IF NOT EXISTS).

Structs§

DeterministicEmbedder
Deterministic, network-free pseudo-embedder.
GatewayEmbedder
OpenAI-compatible /v1/embeddings embedder (the SmooAI LiteLLM gateway).
GatewayReranker
Cross-encoder reranker over the SmooAI gateway’s /v1/rerank endpoint (feature gap G8).
HttpRerankBackend
The real backend: a Cohere/Voyage-style /v1/rerank call over the gateway.
PgConnectorConfigStore
Postgres-backed ConnectorConfigStore over connector_configs.
PgIndexingStore
Postgres-backed IndexingStore over indexing_runs.
PgKnowledgeBase
pgvector knowledge base. Cheap to clone (all fields are Arc/pool handles).
PgMemory
pgvector-backed agent memory, bound to one (organization_id, user_id) namespace. Cheap to clone (all fields are Arc/pool handles + small strings).
PgSettingsStore
Postgres-backed SettingsStore over agent_settings.
PostgresAdapter
Postgres + pgvector storage adapter.
RerankScore
One scored candidate returned by a RerankBackend: the candidate’s index in the request documents array, and its relevance score against the query.

Enums§

InputType
Whether an embedding is for a document being stored or a search query.

Constants§

DEFAULT_EMBEDDING_DIM
Default embedding dimension (Voyage voyage-3-large shape; mirrors smooai’s knowledge_vectors embedding vector(1024)).
DEFAULT_RERANK_MODEL
Default rerank model requested over the gateway (Cohere-compatible). Distinct from the embedding model and the chat model.
OPENAI_SMALL_EMBEDDING_DIM
Dimension returned by OpenAI text-embedding-3-small.

Traits§

Embedder
Turn text into dense vectors. Implementations must return one vector per input string, each of length Embedder::dim.
RerankBackend
A pluggable rerank backend.