In-memory ETS adapter for PhoenixAI.Store.Adapter.
All functions receive an opts keyword list containing a :table key
with the ETS table reference (typically owned by a TableOwner GenServer).
Storage Layout
- Conversations:
{{:conversation, id}, %Conversation{}} - Messages:
{{:message, conversation_id, message_id}, %Message{}} - Facts:
{{:fact, user_id, key}, %Fact{}} - Profiles:
{{:profile, user_id}, %Profile{}}
Summary
Functions
Appends a message to a conversation in ETS. Returns {:error, :not_found} if the conversation does not exist.
Checks whether a conversation with the given ID exists in the ETS table.
Counts conversations in ETS matching the given filters.
Counts events in ETS matching the given filters.
Counts all facts for a user in ETS via a full match scan.
Deletes a conversation and all its messages and cost records from ETS.
Deletes a fact by {user_id, key} from ETS. Always returns :ok.
Deletes a user profile from ETS. Always returns :ok.
Returns all cost records for a conversation from ETS, sorted by recorded_at ascending.
Returns all facts for a user from ETS, sorted by inserted_at ascending.
Returns all messages for a conversation from ETS, sorted by inserted_at ascending.
Returns all conversations from ETS matching the given filters, sorted by inserted_at descending.
Returns a paginated, filtered list of events from ETS with an opaque cursor for the next page.
Loads a conversation by ID from ETS and eagerly populates its messages.
Loads a user profile from ETS. Returns {:error, :not_found} if absent.
Appends an event to the ETS table keyed on {inserted_at, id} for stable ordering.
Inserts or updates a conversation in the ETS table, preserving inserted_at on upsert.
Inserts a cost record into ETS keyed on {conversation_id, record_id}.
Upserts a fact in ETS keyed on {user_id, key}, preserving inserted_at on update.
Upserts a user profile in ETS keyed on user_id, preserving inserted_at on update.
Sums token_count across all messages for a conversation stored in ETS.
Sums total_cost across all cost records matching the given filters in ETS.
Sums token_count across all messages in all conversations belonging to a user in ETS.
Functions
Appends a message to a conversation in ETS. Returns {:error, :not_found} if the conversation does not exist.
Checks whether a conversation with the given ID exists in the ETS table.
Counts conversations in ETS matching the given filters.
Note: O(n) — materializes the full filtered list then counts. Use the Ecto adapter for production workloads requiring efficient counts.
Counts events in ETS matching the given filters.
Counts all facts for a user in ETS via a full match scan.
Deletes a conversation and all its messages and cost records from ETS.
Deletes a fact by {user_id, key} from ETS. Always returns :ok.
Deletes a user profile from ETS. Always returns :ok.
Returns all cost records for a conversation from ETS, sorted by recorded_at ascending.
Returns all facts for a user from ETS, sorted by inserted_at ascending.
Returns all messages for a conversation from ETS, sorted by inserted_at ascending.
Returns all conversations from ETS matching the given filters, sorted by inserted_at descending.
Returns a paginated, filtered list of events from ETS with an opaque cursor for the next page.
Loads a conversation by ID from ETS and eagerly populates its messages.
Loads a user profile from ETS. Returns {:error, :not_found} if absent.
Appends an event to the ETS table keyed on {inserted_at, id} for stable ordering.
Inserts or updates a conversation in the ETS table, preserving inserted_at on upsert.
Inserts a cost record into ETS keyed on {conversation_id, record_id}.
Upserts a fact in ETS keyed on {user_id, key}, preserving inserted_at on update.
Upserts a user profile in ETS keyed on user_id, preserving inserted_at on update.
Sums token_count across all messages for a conversation stored in ETS.
Sums total_cost across all cost records matching the given filters in ETS.
Sums token_count across all messages in all conversations belonging to a user in ETS.