Documentation
¶
Overview ¶
Package neo4j is a history Store backed by Neo4j via the official Go driver (v5).
Storage model:
(:ChatMessage {
conversation_id: "u-42",
seq: <int64 nanos>,
message: "<json>",
created_at: <datetime>
})
A composite index on (`conversation_id`, `seq`) is created by InitializeSchema=true so reads stream in insertion order without a full collection scan. A store-local sequence generator reserves one contiguous range per Write and remains monotonic across local clock regression. Concurrent calls and writes from distinct Store instances have no defined relative order.
Example:
drv, _ := neo4j.NewDriverWithContext("neo4j://...", auth)
defer drv.Close(ctx)
store, _ := neo4jstore.NewStore(ctx, neo4jstore.StoreConfig{
Driver: drv,
Database: "neo4j",
InitializeSchema: true,
})
Index ¶
- Constants
- type Store
- func (s *Store) Clear(ctx context.Context, conversationID history.ConversationID) (err error)
- func (s *Store) Conversations(ctx context.Context) (ids []history.ConversationID, err error)
- func (s *Store) Read(ctx context.Context, conversationID history.ConversationID) (storedMessages []chat.Message, err error)
- func (s *Store) Write(ctx context.Context, conversationID history.ConversationID, ...) (err error)
- type StoreConfig
Constants ¶
const ( DefaultDatabase = "neo4j" DefaultLabel = "ChatMessage" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists messages as Neo4j nodes through a caller-owned driver. It validates dynamic labels before query construction and uses a local monotonic sequence for deterministic reads; ordering across separate Store values remains unspecified.
func (*Store) Clear ¶
Clear deletes every node for conversationID under the configured label. Unknown ids are a no-op.
func (*Store) Conversations ¶
Conversations returns every stored conversation ID in lexical order.
func (*Store) Read ¶
func (s *Store) Read(ctx context.Context, conversationID history.ConversationID) (storedMessages []chat.Message, err error)
Read returns every message stored under conversationID in insertion order (seq ascending).
func (*Store) Write ¶
func (s *Store) Write(ctx context.Context, conversationID history.ConversationID, messages ...chat.Message) (err error)
Write creates a new node per message under conversationID. A reserved sequence range preserves argument order and remains monotonic if the local clock moves backward.
type StoreConfig ¶
type StoreConfig struct {
// Driver is the live Neo4j driver. Required. Callers own its
// lifetime.
Driver neo4j.DriverWithContext
// Database selects the Neo4j database to operate against.
// Optional: defaults to [DefaultDatabase] ("neo4j").
Database string
// Label is the node label used for stored messages. Optional:
// defaults to [DefaultLabel] ("ChatMessage").
Label string
// InitializeSchema, when true, creates an index on
// (conversation_id, seq) for the chosen label. Idempotent.
InitializeSchema bool
}
func (StoreConfig) Validate ¶
func (s StoreConfig) Validate() error