Documentation ¶
Index ¶
- Constants
- Variables
- func CleanDB(t *testing.T, db *bun.DB)
- func CreateSchema(ctx context.Context, appState *models.AppState, db *bun.DB) error
- func GenerateFixtureData(fixtureCount int, outputDir string)
- func LoadFixtures(ctx context.Context, appState *models.AppState, db *bun.DB, fixturePath string) error
- func MigrateEmbeddingDims(ctx context.Context, db *bun.DB, tableName string, dimensions int) error
- func NewPostgresConn(appState *models.AppState) (*bun.DB, error)
- func NewPostgresConnForQueue(appState *models.AppState) (*sql.DB, error)
- type CustomRandSource
- type DocumentCollectionDAO
- func (dc *DocumentCollectionDAO) Create(ctx context.Context) error
- func (dc *DocumentCollectionDAO) CreateDocuments(ctx context.Context, documents []models.Document) ([]uuid.UUID, error)
- func (dc *DocumentCollectionDAO) Delete(ctx context.Context) error
- func (dc *DocumentCollectionDAO) DeleteDocumentsByUUID(ctx context.Context, documentUUIDs []uuid.UUID) error
- func (dc *DocumentCollectionDAO) GetAll(ctx context.Context) ([]models.DocumentCollection, error)
- func (dc *DocumentCollectionDAO) GetByName(ctx context.Context) error
- func (dc *DocumentCollectionDAO) GetCollectionCounts(ctx context.Context) (models.DocumentCollectionCounts, error)
- func (dc *DocumentCollectionDAO) GetDocuments(ctx context.Context, limit int, uuids []uuid.UUID, documentIDs []string) ([]models.Document, error)
- func (dc *DocumentCollectionDAO) SearchDocuments(ctx context.Context, query *models.DocumentSearchPayload, limit int, ...) (*models.DocumentSearchResultPage, error)
- func (dc *DocumentCollectionDAO) Update(ctx context.Context) error
- func (dc *DocumentCollectionDAO) UpdateDocuments(ctx context.Context, documents []models.Document) error
- type DocumentCollectionSchema
- type DocumentSchemaTemplate
- type DocumentStore
- func (ds *DocumentStore) CreateCollection(ctx context.Context, collection models.DocumentCollection) error
- func (ds *DocumentStore) CreateCollectionIndex(ctx context.Context, collectionName string, force bool) error
- func (ds *DocumentStore) CreateDocuments(ctx context.Context, collectionName string, documents []models.Document) ([]uuid.UUID, error)
- func (ds *DocumentStore) DeleteCollection(ctx context.Context, collectionName string) error
- func (ds *DocumentStore) DeleteDocuments(ctx context.Context, collectionName string, documentUUID []uuid.UUID) error
- func (ds *DocumentStore) GetClient() any
- func (ds *DocumentStore) GetCollection(ctx context.Context, collectionName string) (models.DocumentCollection, error)
- func (ds *DocumentStore) GetCollectionList(ctx context.Context) ([]models.DocumentCollection, error)
- func (ds *DocumentStore) GetDocuments(ctx context.Context, collectionName string, uuids []uuid.UUID, ...) ([]models.Document, error)
- func (ds *DocumentStore) OnStart(_ context.Context) error
- func (ds *DocumentStore) SearchCollection(ctx context.Context, query *models.DocumentSearchPayload, limit int, ...) (*models.DocumentSearchResultPage, error)
- func (ds *DocumentStore) Shutdown(_ context.Context) error
- func (ds *DocumentStore) UpdateCollection(ctx context.Context, collection models.DocumentCollection) error
- func (ds *DocumentStore) UpdateDocuments(ctx context.Context, collectionName string, documents []models.Document) error
- type FixtureModel
- type Fixtures
- type IndexStatus
- type JSONQuery
- type MemoryDAO
- func (m *MemoryDAO) Create(ctx context.Context, memoryMessages *models.Memory, skipNotify bool) error
- func (m *MemoryDAO) Get(ctx context.Context, lastNMessages int) (*models.Memory, error)
- func (m *MemoryDAO) Search(ctx context.Context, query *models.MemorySearchPayload, limit int) ([]models.MemorySearchResult, error)
- type MessageDAO
- func (dao *MessageDAO) Create(ctx context.Context, message *models.Message) (*models.Message, error)
- func (dao *MessageDAO) CreateEmbeddings(ctx context.Context, embeddings []models.TextData) error
- func (dao *MessageDAO) CreateMany(ctx context.Context, messages []models.Message) ([]models.Message, error)
- func (dao *MessageDAO) Delete(ctx context.Context, messageUUID uuid.UUID) error
- func (dao *MessageDAO) Get(ctx context.Context, messageUUID uuid.UUID) (*models.Message, error)
- func (dao *MessageDAO) GetEmbedding(ctx context.Context, messageUUID uuid.UUID) (*models.TextData, error)
- func (dao *MessageDAO) GetEmbeddingListBySession(ctx context.Context) ([]models.TextData, error)
- func (dao *MessageDAO) GetLastN(ctx context.Context, lastNMessages int, beforeUUID uuid.UUID) ([]models.Message, error)
- func (dao *MessageDAO) GetListBySession(ctx context.Context, currentPage int, pageSize int) (*models.MessageListResponse, error)
- func (dao *MessageDAO) GetListByUUID(ctx context.Context, messageUUIDs []uuid.UUID) ([]models.Message, error)
- func (dao *MessageDAO) GetSinceLastSummary(ctx context.Context, lastSummary *models.Summary, memoryWindow int) ([]models.Message, error)
- func (dao *MessageDAO) Update(ctx context.Context, message *models.Message, includeContent bool, ...) error
- func (dao *MessageDAO) UpdateMany(ctx context.Context, messages []models.Message, includeContent bool, ...) error
- type MessageStoreSchema
- type MessageVectorStoreSchema
- type PostgresMemoryStore
- func (pms *PostgresMemoryStore) Close() error
- func (pms *PostgresMemoryStore) CreateMessageEmbeddings(ctx context.Context, sessionID string, embeddings []models.TextData) error
- func (pms *PostgresMemoryStore) CreateSession(ctx context.Context, session *models.CreateSessionRequest) (*models.Session, error)
- func (pms *PostgresMemoryStore) CreateSummary(ctx context.Context, sessionID string, summary *models.Summary) error
- func (pms *PostgresMemoryStore) DeleteSession(ctx context.Context, sessionID string) error
- func (pms *PostgresMemoryStore) GetClient() *bun.DB
- func (pms *PostgresMemoryStore) GetMemory(ctx context.Context, sessionID string, lastNMessages int) (*models.Memory, error)
- func (pms *PostgresMemoryStore) GetMessageEmbeddings(ctx context.Context, sessionID string) ([]models.TextData, error)
- func (pms *PostgresMemoryStore) GetMessageList(ctx context.Context, sessionID string, pageNumber int, pageSize int) (*models.MessageListResponse, error)
- func (pms *PostgresMemoryStore) GetMessagesByUUID(ctx context.Context, sessionID string, uuids []uuid.UUID) ([]models.Message, error)
- func (pms *PostgresMemoryStore) GetSession(ctx context.Context, sessionID string) (*models.Session, error)
- func (pms *PostgresMemoryStore) GetSummary(ctx context.Context, sessionID string) (*models.Summary, error)
- func (pms *PostgresMemoryStore) GetSummaryByUUID(ctx context.Context, sessionID string, uuid uuid.UUID) (*models.Summary, error)
- func (pms *PostgresMemoryStore) GetSummaryList(ctx context.Context, sessionID string, pageNumber int, pageSize int) (*models.SummaryListResponse, error)
- func (pms *PostgresMemoryStore) ListSessions(ctx context.Context, cursor int64, limit int) ([]*models.Session, error)
- func (pms *PostgresMemoryStore) ListSessionsOrdered(ctx context.Context, pageNumber int, pageSize int, orderedBy string, asc bool) (*models.SessionListResponse, error)
- func (pms *PostgresMemoryStore) OnStart(ctx context.Context) error
- func (pms *PostgresMemoryStore) PurgeDeleted(ctx context.Context) error
- func (pms *PostgresMemoryStore) PutMemory(ctx context.Context, sessionID string, memoryMessages *models.Memory, ...) error
- func (pms *PostgresMemoryStore) PutSummaryEmbedding(ctx context.Context, sessionID string, embedding *models.TextData) error
- func (pms *PostgresMemoryStore) SearchMemory(ctx context.Context, sessionID string, query *models.MemorySearchPayload, ...) ([]models.MemorySearchResult, error)
- func (pms *PostgresMemoryStore) UpdateMessages(ctx context.Context, sessionID string, messages []models.Message, ...) error
- func (pms *PostgresMemoryStore) UpdateSession(ctx context.Context, session *models.UpdateSessionRequest) (*models.Session, error)
- func (pms *PostgresMemoryStore) UpdateSummary(ctx context.Context, sessionID string, summary *models.Summary, ...) error
- type Row
- type SessionDAO
- func (dao *SessionDAO) Create(ctx context.Context, session *models.CreateSessionRequest) (*models.Session, error)
- func (dao *SessionDAO) Delete(ctx context.Context, sessionID string) error
- func (dao *SessionDAO) Get(ctx context.Context, sessionID string) (*models.Session, error)
- func (dao *SessionDAO) ListAll(ctx context.Context, cursor int64, limit int) ([]*models.Session, error)
- func (dao *SessionDAO) ListAllOrdered(ctx context.Context, pageNumber int, pageSize int, orderBy string, asc bool) (*models.SessionListResponse, error)
- func (dao *SessionDAO) Update(ctx context.Context, session *models.UpdateSessionRequest, isPrivileged bool) (*models.Session, error)
- type SessionSchema
- type SummaryDAO
- func (s *SummaryDAO) Create(ctx context.Context, summary *models.Summary) (*models.Summary, error)
- func (s *SummaryDAO) Get(ctx context.Context) (*models.Summary, error)
- func (s *SummaryDAO) GetByUUID(ctx context.Context, uuid uuid.UUID) (*models.Summary, error)
- func (s *SummaryDAO) GetEmbeddings(ctx context.Context) ([]models.TextData, error)
- func (s *SummaryDAO) GetList(ctx context.Context, currentPage int, pageSize int) (*models.SummaryListResponse, error)
- func (s *SummaryDAO) PutEmbedding(ctx context.Context, embedding *models.TextData) error
- func (s *SummaryDAO) Update(ctx context.Context, summary *models.Summary, includeContent bool) (*models.Summary, error)
- type SummaryStoreSchema
- type SummaryVectorStoreSchema
- type UserSchema
- type UserStoreDAO
- func (dao *UserStoreDAO) Create(ctx context.Context, user *models.CreateUserRequest) (*models.User, error)
- func (dao *UserStoreDAO) Delete(ctx context.Context, userID string) error
- func (dao *UserStoreDAO) Get(ctx context.Context, userID string) (*models.User, error)
- func (dao *UserStoreDAO) GetSessions(ctx context.Context, userID string) ([]*models.Session, error)
- func (dao *UserStoreDAO) ListAll(ctx context.Context, cursor int64, limit int) ([]*models.User, error)
- func (dao *UserStoreDAO) ListAllOrdered(ctx context.Context, pageNumber int, pageSize int, orderBy string, asc bool) (*models.UserListResponse, error)
- func (dao *UserStoreDAO) Update(ctx context.Context, user *models.UpdateUserRequest, isPrivileged bool) (*models.User, error)
- type VectorColIndex
Constants ¶
const DefaultDocEmbeddingChunkSize = 1000
const DefaultDocumentSearchLimit = 20
const DefaultEFSearch = 100
const DefaultMMRLambda = 0.5
const DefaultMMRMultiplier = 2
const DefaultMemorySearchLimit = 10
const EmbeddingColName = "embedding"
const IndexTimeout = 1 * time.Hour
const MaxParallelWorkersPerGather = 4
const MinRowsForIndex = 10000
MinRowsForIndex is the minimum number of rows required to create an index. The pgvector docs recommend creating the index after a representative sample of data is loaded. This is a guesstimate.
Variables ¶
var IndexMutexMap = make(map[string]*sync.Mutex)
IndexMutexMap stores a mutex for each collection.
Functions ¶
func CreateSchema ¶ added in v0.11.0
CreateSchema creates the db schema if it does not exist.
func GenerateFixtureData ¶ added in v0.11.0
func LoadFixtures ¶ added in v0.11.0
func MigrateEmbeddingDims ¶ added in v0.17.0
func MigrateEmbeddingDims( ctx context.Context, db *bun.DB, tableName string, dimensions int, ) error
MigrateEmbeddingDims drops the old embedding column and creates a new one with the correct dimensions.
func NewPostgresConn ¶
NewPostgresConn creates a new bun.DB connection to a postgres database using the provided DSN. The connection is configured to pool connections based on the number of PROCs available.
Types ¶
type CustomRandSource ¶ added in v0.12.0
func (*CustomRandSource) Intn ¶ added in v0.12.0
func (s *CustomRandSource) Intn(n int) int
Intn Override
type DocumentCollectionDAO ¶
type DocumentCollectionDAO struct { models.DocumentCollection // contains filtered or unexported fields }
func NewDocumentCollectionDAO ¶
func NewDocumentCollectionDAO( appState *models.AppState, db *bun.DB, collection models.DocumentCollection, ) *DocumentCollectionDAO
func (*DocumentCollectionDAO) Create ¶
func (dc *DocumentCollectionDAO) Create( ctx context.Context, ) error
Create inserts a collection into the collections table and creates a table for the collection's documents.
func (*DocumentCollectionDAO) CreateDocuments ¶
func (dc *DocumentCollectionDAO) CreateDocuments( ctx context.Context, documents []models.Document, ) ([]uuid.UUID, error)
CreateDocuments inserts the given documents into the given collection.
func (*DocumentCollectionDAO) Delete ¶
func (dc *DocumentCollectionDAO) Delete(ctx context.Context) error
Delete deletes a collection from the collections table and drops the collection's document table.
func (*DocumentCollectionDAO) DeleteDocumentsByUUID ¶
func (dc *DocumentCollectionDAO) DeleteDocumentsByUUID( ctx context.Context, documentUUIDs []uuid.UUID, ) error
DeleteDocumentsByUUID deletes a single document from a collection in the SqlDB, identified by its UUID.
func (*DocumentCollectionDAO) GetAll ¶
func (dc *DocumentCollectionDAO) GetAll( ctx context.Context, ) ([]models.DocumentCollection, error)
GetAll returns a list of all collections from the collections table.
func (*DocumentCollectionDAO) GetByName ¶
func (dc *DocumentCollectionDAO) GetByName( ctx context.Context, ) error
GetByName returns a collection from the collections table by name.
func (*DocumentCollectionDAO) GetCollectionCounts ¶ added in v0.12.0
func (dc *DocumentCollectionDAO) GetCollectionCounts( ctx context.Context, ) (models.DocumentCollectionCounts, error)
GetCollectionCounts returns the number of documents and embedded documents
func (*DocumentCollectionDAO) GetDocuments ¶
func (dc *DocumentCollectionDAO) GetDocuments( ctx context.Context, limit int, uuids []uuid.UUID, documentIDs []string, ) ([]models.Document, error)
GetDocuments retrieves documents. If `documents` is non-Nil, it will use the document UUIDs to retrieve these documents. Otherwise, it will retrieve all documents. If limit is greater than 0, it will only retrieve limit many documents.
func (*DocumentCollectionDAO) SearchDocuments ¶
func (dc *DocumentCollectionDAO) SearchDocuments(ctx context.Context, query *models.DocumentSearchPayload, limit int, pageNumber int, pageSize int) (*models.DocumentSearchResultPage, error)
SearchDocuments searches for documents in a collection. Currently pagination is not supported.
func (*DocumentCollectionDAO) Update ¶
func (dc *DocumentCollectionDAO) Update( ctx context.Context, ) error
Update updates a collection in the collections table.
func (*DocumentCollectionDAO) UpdateDocuments ¶
func (dc *DocumentCollectionDAO) UpdateDocuments( ctx context.Context, documents []models.Document, ) error
UpdateDocuments updates the document_id, metadata, and embedding columns of the given documents in the given collection. The documents must have non-nil uuids.
**IMPORTANT:** We determine which columns to update based on the fields that are non-zero in the given documents. This means that all documents must have data for the same fields. If a document is missing data for a field, there could be data loss.
type DocumentCollectionSchema ¶
type DocumentCollectionSchema struct { bun.BaseModel `bun:"table:document_collection,alias:dc" yaml:"-"` models.DocumentCollection ` yaml:",inline"` }
DocumentCollectionSchema represents the schema for the DocumentCollectionDAO table.
func (*DocumentCollectionSchema) AfterCreateTable ¶
func (*DocumentCollectionSchema) AfterCreateTable( ctx context.Context, query *bun.CreateTableQuery, ) error
func (*DocumentCollectionSchema) BeforeAppendModel ¶ added in v0.12.0
type DocumentSchemaTemplate ¶
type DocumentSchemaTemplate struct { bun.BaseModel `bun:"table:document,alias:d"` models.DocumentBase }
DocumentSchemaTemplate represents the schema template for Document tables. TextData is manually added when createDocumentTable is run in order to set the correct dimensions. This means the embedding is not returned when querying using bun.
type DocumentStore ¶
type DocumentStore struct { store.BaseDocumentStore[*bun.DB] // contains filtered or unexported fields }
func NewDocumentStore ¶
func NewDocumentStore( ctx context.Context, appState *models.AppState, client *bun.DB, ) (*DocumentStore, error)
NewDocumentStore returns a new DocumentStore. Use this to correctly initialize the store.
func (*DocumentStore) CreateCollection ¶
func (ds *DocumentStore) CreateCollection( ctx context.Context, collection models.DocumentCollection, ) error
func (*DocumentStore) CreateCollectionIndex ¶
func (*DocumentStore) CreateDocuments ¶
func (*DocumentStore) DeleteCollection ¶
func (ds *DocumentStore) DeleteCollection( ctx context.Context, collectionName string, ) error
func (*DocumentStore) DeleteDocuments ¶
func (*DocumentStore) GetClient ¶
func (ds *DocumentStore) GetClient() any
func (*DocumentStore) GetCollection ¶
func (ds *DocumentStore) GetCollection( ctx context.Context, collectionName string, ) (models.DocumentCollection, error)
func (*DocumentStore) GetCollectionList ¶
func (ds *DocumentStore) GetCollectionList( ctx context.Context, ) ([]models.DocumentCollection, error)
func (*DocumentStore) GetDocuments ¶
func (*DocumentStore) SearchCollection ¶
func (ds *DocumentStore) SearchCollection( ctx context.Context, query *models.DocumentSearchPayload, limit int, pageNumber int, pageSize int, ) (*models.DocumentSearchResultPage, error)
func (*DocumentStore) UpdateCollection ¶
func (ds *DocumentStore) UpdateCollection( ctx context.Context, collection models.DocumentCollection, ) error
func (*DocumentStore) UpdateDocuments ¶
type FixtureModel ¶ added in v0.11.0
type Fixtures ¶ added in v0.11.0
type Fixtures[T Row] []FixtureModel[T]
type IndexStatus ¶ added in v0.13.0
type MemoryDAO ¶ added in v0.20.0
type MemoryDAO struct {
// contains filtered or unexported fields
}
MemoryDAO is a data access object for Memory. A Memory is an overlay over Messages and Summaries. It is used to retrieve a set of messages and a summary for a given sessionID, to store a new set of messages from a chat client, and to search for messages and summaries.
func NewMemoryDAO ¶ added in v0.20.0
NewMemoryDAO creates a new MemoryDAO.
func (*MemoryDAO) Create ¶ added in v0.20.0
func (m *MemoryDAO) Create( ctx context.Context, memoryMessages *models.Memory, skipNotify bool, ) error
Create stores a Memory for a given sessionID. If the SessionID doesn't exist, a new one is created. If skipNotify is true, the new messages will not be published to the message queue router.
func (*MemoryDAO) Get ¶ added in v0.20.0
Get returns the most recent Summary and a list of messages for a given sessionID. Get returns:
- the most recent Summary, if one exists
- the lastNMessages messages, if lastNMessages > 0
- all messages since the last SummaryPoint, if lastNMessages == 0
- if no Summary (and no SummaryPoint) exists and lastNMessages == 0, returns all undeleted messages up to the configured message window
type MessageDAO ¶ added in v0.20.0
type MessageDAO struct {
// contains filtered or unexported fields
}
func NewMessageDAO ¶ added in v0.20.0
func (*MessageDAO) Create ¶ added in v0.20.0
func (dao *MessageDAO) Create( ctx context.Context, message *models.Message, ) (*models.Message, error)
Create creates a new message for a session. Create does not create a session if it does not exist.
func (*MessageDAO) CreateEmbeddings ¶ added in v0.20.0
CreateEmbeddings saves message embeddings for a set of given messages
func (*MessageDAO) CreateMany ¶ added in v0.20.0
func (dao *MessageDAO) CreateMany( ctx context.Context, messages []models.Message, ) ([]models.Message, error)
CreateMany creates a batch of messages for a session.
func (*MessageDAO) GetEmbedding ¶ added in v0.20.0
func (*MessageDAO) GetEmbeddingListBySession ¶ added in v0.20.0
GetEmbeddingListBySession retrieves all message embeddings for a session.
func (*MessageDAO) GetLastN ¶ added in v0.20.0
func (dao *MessageDAO) GetLastN( ctx context.Context, lastNMessages int, beforeUUID uuid.UUID, ) ([]models.Message, error)
GetLastN retrieves the last N messages for a session. If uuid is provided, it will get the last N messages before and including the provided beforeUUID. Results are returned in ascending order of creation
func (*MessageDAO) GetListBySession ¶ added in v0.20.0
func (dao *MessageDAO) GetListBySession( ctx context.Context, currentPage int, pageSize int) (*models.MessageListResponse, error)
GetListBySession retrieves a list of messages for a session. The list is paginated.
func (*MessageDAO) GetListByUUID ¶ added in v0.20.0
func (dao *MessageDAO) GetListByUUID( ctx context.Context, messageUUIDs []uuid.UUID, ) ([]models.Message, error)
GetListByUUID retrieves a list of messages by their UUIDs. Does not reorder the messages.
func (*MessageDAO) GetSinceLastSummary ¶ added in v0.20.0
func (dao *MessageDAO) GetSinceLastSummary( ctx context.Context, lastSummary *models.Summary, memoryWindow int, ) ([]models.Message, error)
GetSinceLastSummary retrieves messages since the last summary point, limited by the memory window. If there is no last summary point, all messages are returned, limited by the memory window. Results are returned in ascending order of creation
func (*MessageDAO) Update ¶ added in v0.20.0
func (dao *MessageDAO) Update(ctx context.Context, message *models.Message, includeContent bool, isPrivileged bool) error
Update updates a message by its UUID. Metadata is updated via a merge. If includeContent is true, the content and role fields are updated, too.
func (*MessageDAO) UpdateMany ¶ added in v0.20.0
func (dao *MessageDAO) UpdateMany(ctx context.Context, messages []models.Message, includeContent bool, isPrivileged bool) error
UpdateMany updates a batch of messages by their UUIDs. Metadata is updated via a merge.
type MessageStoreSchema ¶
type MessageStoreSchema struct { bun.BaseModel `bun:"table:message,alias:m" yaml:"-"` UUID uuid.UUID `bun:",pk,type:uuid,default:gen_random_uuid()" yaml:"uuid"` // ID is used only for sorting / slicing purposes as we can't sort by CreatedAt for messages created simultaneously ID int64 `bun:",autoincrement" yaml:"id,omitempty"` CreatedAt time.Time `bun:"type:timestamptz,notnull,default:current_timestamp" yaml:"created_at,omitempty"` UpdatedAt time.Time `bun:"type:timestamptz,nullzero,default:current_timestamp" yaml:"updated_at,omitempty"` DeletedAt time.Time `bun:"type:timestamptz,soft_delete,nullzero" yaml:"deleted_at,omitempty"` SessionID string `bun:",notnull" yaml:"session_id,omitempty"` Role string `bun:",notnull" yaml:"role,omitempty"` Content string `bun:",notnull" yaml:"content,omitempty"` TokenCount int `bun:",notnull" yaml:"token_count,omitempty"` Metadata map[string]interface{} `bun:"type:jsonb,nullzero,json_use_number" yaml:"metadata,omitempty"` Session *SessionSchema `bun:"rel:belongs-to,join:session_id=session_id,on_delete:cascade" yaml:"-"` }
func (*MessageStoreSchema) AfterCreateTable ¶
func (*MessageStoreSchema) AfterCreateTable( ctx context.Context, query *bun.CreateTableQuery, ) error
func (*MessageStoreSchema) BeforeAppendModel ¶ added in v0.12.0
type MessageVectorStoreSchema ¶
type MessageVectorStoreSchema struct { bun.BaseModel `bun:"table:message_embedding,alias:me"` UUID uuid.UUID `bun:",pk,type:uuid,default:gen_random_uuid()"` CreatedAt time.Time `bun:"type:timestamptz,notnull,default:current_timestamp"` UpdatedAt time.Time `bun:"type:timestamptz,nullzero,default:current_timestamp"` DeletedAt time.Time `bun:"type:timestamptz,soft_delete,nullzero"` SessionID string `bun:",notnull"` MessageUUID uuid.UUID `bun:"type:uuid,notnull,unique"` Embedding pgvector.Vector `bun:"type:vector(1536)"` IsEmbedded bool `bun:"type:bool,notnull,default:false"` Session *SessionSchema `bun:"rel:belongs-to,join:session_id=session_id,on_delete:cascade"` Message *MessageStoreSchema `bun:"rel:belongs-to,join:message_uuid=uuid,on_delete:cascade"` }
MessageVectorStoreSchema stores the embeddings for a message.
func (*MessageVectorStoreSchema) AfterCreateTable ¶
func (*MessageVectorStoreSchema) AfterCreateTable( ctx context.Context, query *bun.CreateTableQuery, ) error
func (*MessageVectorStoreSchema) BeforeAppendModel ¶ added in v0.12.0
type PostgresMemoryStore ¶
type PostgresMemoryStore struct { store.BaseMemoryStore[*bun.DB] SessionStore *SessionDAO // contains filtered or unexported fields }
func NewPostgresMemoryStore ¶
func NewPostgresMemoryStore( appState *models.AppState, client *bun.DB, ) (*PostgresMemoryStore, error)
NewPostgresMemoryStore returns a new PostgresMemoryStore. Use this to correctly initialize the store.
func (*PostgresMemoryStore) Close ¶
func (pms *PostgresMemoryStore) Close() error
func (*PostgresMemoryStore) CreateMessageEmbeddings ¶ added in v0.20.0
func (*PostgresMemoryStore) CreateSession ¶ added in v0.11.0
func (pms *PostgresMemoryStore) CreateSession( ctx context.Context, session *models.CreateSessionRequest, ) (*models.Session, error)
CreateSession creates or updates a Session for a given sessionID.
func (*PostgresMemoryStore) CreateSummary ¶ added in v0.20.0
func (*PostgresMemoryStore) DeleteSession ¶
func (pms *PostgresMemoryStore) DeleteSession(ctx context.Context, sessionID string) error
DeleteSession deletes a session from the memory store. This is a soft Delete.
func (*PostgresMemoryStore) GetClient ¶
func (pms *PostgresMemoryStore) GetClient() *bun.DB
func (*PostgresMemoryStore) GetMemory ¶
func (pms *PostgresMemoryStore) GetMemory( ctx context.Context, sessionID string, lastNMessages int, ) (*models.Memory, error)
GetMemory returns the most recent Summary and a list of messages for a given sessionID. GetMemory returns:
- the most recent Summary, if one exists
- the lastNMessages messages, if lastNMessages > 0
- all messages since the last SummaryPoint, if lastNMessages == 0
- if no Summary (and no SummaryPoint) exists and lastNMessages == 0, returns all undeleted messages up to the configured message window
func (*PostgresMemoryStore) GetMessageEmbeddings ¶ added in v0.17.0
func (*PostgresMemoryStore) GetMessageList ¶ added in v0.12.0
func (pms *PostgresMemoryStore) GetMessageList( ctx context.Context, sessionID string, pageNumber int, pageSize int, ) (*models.MessageListResponse, error)
GetMessageList retrieves a list of messages for a given sessionID. Paginated by cursor and limit.
func (*PostgresMemoryStore) GetMessagesByUUID ¶ added in v0.17.0
func (*PostgresMemoryStore) GetSession ¶
func (pms *PostgresMemoryStore) GetSession( ctx context.Context, sessionID string, ) (*models.Session, error)
GetSession retrieves a Session for a given sessionID.
func (*PostgresMemoryStore) GetSummary ¶
func (*PostgresMemoryStore) GetSummaryByUUID ¶ added in v0.17.0
func (*PostgresMemoryStore) GetSummaryList ¶ added in v0.12.0
func (pms *PostgresMemoryStore) GetSummaryList( ctx context.Context, sessionID string, pageNumber int, pageSize int, ) (*models.SummaryListResponse, error)
func (*PostgresMemoryStore) ListSessions ¶ added in v0.11.0
func (pms *PostgresMemoryStore) ListSessions( ctx context.Context, cursor int64, limit int, ) ([]*models.Session, error)
ListSessions returns a list of all Sessions.
func (*PostgresMemoryStore) ListSessionsOrdered ¶ added in v0.12.0
func (pms *PostgresMemoryStore) ListSessionsOrdered( ctx context.Context, pageNumber int, pageSize int, orderedBy string, asc bool, ) (*models.SessionListResponse, error)
ListSessionsOrdered returns an ordered list of all Sessions, paginated by pageNumber and pageSize. orderedBy is the column to order by. asc is a boolean indicating whether to order ascending or descending.
func (*PostgresMemoryStore) OnStart ¶
func (pms *PostgresMemoryStore) OnStart( ctx context.Context, ) error
func (*PostgresMemoryStore) PurgeDeleted ¶
func (pms *PostgresMemoryStore) PurgeDeleted(ctx context.Context) error
func (*PostgresMemoryStore) PutSummaryEmbedding ¶ added in v0.17.0
func (*PostgresMemoryStore) SearchMemory ¶
func (pms *PostgresMemoryStore) SearchMemory( ctx context.Context, sessionID string, query *models.MemorySearchPayload, limit int, ) ([]models.MemorySearchResult, error)
func (*PostgresMemoryStore) UpdateMessages ¶ added in v0.20.0
func (*PostgresMemoryStore) UpdateSession ¶ added in v0.11.0
func (pms *PostgresMemoryStore) UpdateSession( ctx context.Context, session *models.UpdateSessionRequest, ) (*models.Session, error)
UpdateSession creates or updates a Session for a given sessionID.
func (*PostgresMemoryStore) UpdateSummary ¶ added in v0.20.0
type Row ¶ added in v0.11.0
type Row interface { UserSchema | SessionSchema | DocumentCollectionSchema | MessageStoreSchema }
type SessionDAO ¶ added in v0.11.0
type SessionDAO struct {
// contains filtered or unexported fields
}
SessionDAO implements the SessionManager interface.
func NewSessionDAO ¶ added in v0.11.0
func NewSessionDAO(db *bun.DB) *SessionDAO
NewSessionDAO is a constructor for the SessionDAO struct. It takes a pointer to a bun.DB instance and returns a pointer to a new SessionDAO instance.
func (*SessionDAO) Create ¶ added in v0.11.0
func (dao *SessionDAO) Create( ctx context.Context, session *models.CreateSessionRequest, ) (*models.Session, error)
Create creates a new session in the database. It takes a context and a pointer to a CreateSessionRequest struct. It returns a pointer to the created Session struct or an error if the creation fails.
func (*SessionDAO) Delete ¶ added in v0.11.0
func (dao *SessionDAO) Delete(ctx context.Context, sessionID string) error
Delete soft-deletes a session from the database by its sessionID. It also soft-deletes all messages, message embeddings, and summaries associated with the session.
func (*SessionDAO) Get ¶ added in v0.11.0
Get retrieves a session from the database by its sessionID. It takes a context and a session ID string. It returns a pointer to the retrieved Session struct or an error if the retrieval fails.
func (*SessionDAO) ListAll ¶ added in v0.11.0
func (dao *SessionDAO) ListAll( ctx context.Context, cursor int64, limit int, ) ([]*models.Session, error)
ListAll retrieves all sessions from the database. It takes a context, a cursor int64, and a limit int. It returns a slice of pointers to Session structs or an error if the retrieval fails.
func (*SessionDAO) ListAllOrdered ¶ added in v0.12.0
func (dao *SessionDAO) ListAllOrdered( ctx context.Context, pageNumber int, pageSize int, orderBy string, asc bool, ) (*models.SessionListResponse, error)
func (*SessionDAO) Update ¶ added in v0.11.0
func (dao *SessionDAO) Update( ctx context.Context, session *models.UpdateSessionRequest, isPrivileged bool, ) (*models.Session, error)
Update updates a session in the database. It takes a context, a pointer to a UpdateSessionRequest struct, and a boolean indicating whether the caller is privileged. It returns an error if the update fails. Note: Update will update soft-deleted sessions and undelete them. Messages and message embeddings are not undeleted.
type SessionSchema ¶
type SessionSchema struct { bun.BaseModel `bun:"table:session,alias:s" yaml:"-"` UUID uuid.UUID `bun:",pk,type:uuid,default:gen_random_uuid()" yaml:"uuid,omitempty"` ID int64 `bun:",autoincrement" yaml:"id,omitempty"` // used as a cursor for pagination SessionID string `bun:",unique,notnull" yaml:"session_id,omitempty"` CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp" yaml:"created_at,omitempty"` UpdatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp" yaml:"updated_at,omitempty"` DeletedAt time.Time `bun:"type:timestamptz,soft_delete,nullzero" yaml:"deleted_at,omitempty"` Metadata map[string]interface{} `bun:"type:jsonb,nullzero,json_use_number" yaml:"metadata,omitempty"` // UserUUID must be pointer type in order to be nullable UserID *string `bun:"," yaml:"user_id,omitempty"` User *UserSchema `bun:"rel:belongs-to,join:user_id=user_id,on_delete:cascade" yaml:"-"` }
func (*SessionSchema) AfterCreateTable ¶
func (*SessionSchema) AfterCreateTable( ctx context.Context, query *bun.CreateTableQuery, ) error
func (*SessionSchema) BeforeAppendModel ¶ added in v0.12.0
type SummaryDAO ¶ added in v0.20.0
type SummaryDAO struct {
// contains filtered or unexported fields
}
func NewSummaryDAO ¶ added in v0.20.0
NewSummaryDAO creates a new SummaryDAO.
func (*SummaryDAO) Create ¶ added in v0.20.0
func (s *SummaryDAO) Create( ctx context.Context, summary *models.Summary, ) (*models.Summary, error)
Create stores a new summary for a session. The SummaryPointUUID is the UUID of the most recent message in the session when the summary was created.
func (*SummaryDAO) GetEmbeddings ¶ added in v0.20.0
GetEmbeddings all summary embeddings for a session. Note: Does not return the summary content.
func (*SummaryDAO) GetList ¶ added in v0.20.0
func (s *SummaryDAO) GetList(ctx context.Context, currentPage int, pageSize int, ) (*models.SummaryListResponse, error)
GetList returns a list of summaries for a session
func (*SummaryDAO) PutEmbedding ¶ added in v0.20.0
PutEmbedding stores a summary embedding
type SummaryStoreSchema ¶
type SummaryStoreSchema struct { bun.BaseModel `bun:"table:summary,alias:su" ,yaml:"-"` UUID uuid.UUID `bun:",pk,type:uuid,default:gen_random_uuid()"` CreatedAt time.Time `bun:"type:timestamptz,notnull,default:current_timestamp"` UpdatedAt time.Time `bun:"type:timestamptz,nullzero,default:current_timestamp"` DeletedAt time.Time `bun:"type:timestamptz,soft_delete,nullzero"` SessionID string `bun:",notnull"` Content string `bun:",nullzero"` // allow null as we might want to use Metadata without a summary Metadata map[string]interface{} `bun:"type:jsonb,nullzero,json_use_number"` TokenCount int `bun:",notnull"` SummaryPointUUID uuid.UUID `bun:"type:uuid,notnull,unique"` // the UUID of the most recent message that was used to create the summary Session *SessionSchema `bun:"rel:belongs-to,join:session_id=session_id,on_delete:cascade"` Message *MessageStoreSchema `bun:"rel:belongs-to,join:summary_point_uuid=uuid,on_delete:cascade"` }
func (*SummaryStoreSchema) AfterCreateTable ¶
func (*SummaryStoreSchema) AfterCreateTable( ctx context.Context, query *bun.CreateTableQuery, ) error
func (*SummaryStoreSchema) BeforeAppendModel ¶ added in v0.12.0
type SummaryVectorStoreSchema ¶ added in v0.17.0
type SummaryVectorStoreSchema struct { bun.BaseModel `bun:"table:summary_embedding,alias:se" yaml:"-"` UUID uuid.UUID `bun:",pk,type:uuid,default:gen_random_uuid()"` CreatedAt time.Time `bun:"type:timestamptz,notnull,default:current_timestamp"` UpdatedAt time.Time `bun:"type:timestamptz,nullzero,default:current_timestamp"` DeletedAt time.Time `bun:"type:timestamptz,soft_delete,nullzero"` SessionID string `bun:",notnull"` SummaryUUID uuid.UUID `bun:"type:uuid,notnull,unique"` Embedding pgvector.Vector `bun:"type:vector(1536)"` IsEmbedded bool `bun:"type:bool,notnull,default:false"` Summary *SummaryStoreSchema `bun:"rel:belongs-to,join:summary_uuid=uuid,on_delete:cascade"` Session *SessionSchema `bun:"rel:belongs-to,join:session_id=session_id,on_delete:cascade"` }
func (*SummaryVectorStoreSchema) AfterCreateTable ¶ added in v0.17.0
func (*SummaryVectorStoreSchema) AfterCreateTable( ctx context.Context, query *bun.CreateTableQuery, ) error
func (*SummaryVectorStoreSchema) BeforeAppendModel ¶ added in v0.17.0
type UserSchema ¶ added in v0.11.0
type UserSchema struct { bun.BaseModel `bun:"table:users,alias:u" yaml:"-"` UUID uuid.UUID `bun:",pk,type:uuid,default:gen_random_uuid()" yaml:"uuid,omitempty"` ID int64 `bun:",autoincrement" yaml:"id,omitempty"` // used as a cursor for pagination CreatedAt time.Time `bun:"type:timestamptz,notnull,default:current_timestamp" yaml:"created_at,omitempty"` UpdatedAt time.Time `bun:"type:timestamptz,nullzero,default:current_timestamp" yaml:"updated_at,omitempty"` DeletedAt time.Time `bun:"type:timestamptz,soft_delete,nullzero" yaml:"deleted_at,omitempty"` UserID string `bun:",unique,notnull" yaml:"user_id,omitempty"` Email string `bun:"," yaml:"email,omitempty"` FirstName string `bun:"," yaml:"first_name,omitempty"` LastName string `bun:"," yaml:"last_name,omitempty"` Metadata map[string]interface{} `bun:"type:jsonb,nullzero,json_use_number" yaml:"metadata,omitempty"` }
func (*UserSchema) AfterCreateTable ¶ added in v0.11.0
func (*UserSchema) AfterCreateTable( ctx context.Context, query *bun.CreateTableQuery, ) error
func (*UserSchema) BeforeAppendModel ¶ added in v0.12.0
type UserStoreDAO ¶ added in v0.11.0
type UserStoreDAO struct {
// contains filtered or unexported fields
}
func NewUserStoreDAO ¶ added in v0.11.0
func NewUserStoreDAO(db *bun.DB) *UserStoreDAO
func (*UserStoreDAO) Create ¶ added in v0.11.0
func (dao *UserStoreDAO) Create( ctx context.Context, user *models.CreateUserRequest, ) (*models.User, error)
Create creates a new user.
func (*UserStoreDAO) Delete ¶ added in v0.11.0
func (dao *UserStoreDAO) Delete(ctx context.Context, userID string) error
Delete deletes a user.
func (*UserStoreDAO) GetSessions ¶ added in v0.11.0
func (dao *UserStoreDAO) GetSessions( ctx context.Context, userID string, ) ([]*models.Session, error)
GetSessions gets all sessions for a user.
func (*UserStoreDAO) ListAll ¶ added in v0.11.0
func (dao *UserStoreDAO) ListAll( ctx context.Context, cursor int64, limit int, ) ([]*models.User, error)
ListAll lists all users. The cursor is used to paginate results.
func (*UserStoreDAO) ListAllOrdered ¶ added in v0.12.0
func (dao *UserStoreDAO) ListAllOrdered( ctx context.Context, pageNumber int, pageSize int, orderBy string, asc bool, ) (*models.UserListResponse, error)
type VectorColIndex ¶
type VectorColIndex struct { Collection models.DocumentCollection ColName string RowCount int ListCount int ProbeCount int // contains filtered or unexported fields }
func NewVectorColIndex ¶
func NewVectorColIndex( ctx context.Context, appState *models.AppState, collection models.DocumentCollection, ) (*VectorColIndex, error)
func (*VectorColIndex) CalculateListCount ¶
func (vci *VectorColIndex) CalculateListCount() error
CalculateListCount calculates the number of lists to use for the index.
func (*VectorColIndex) CalculateProbes ¶
func (vci *VectorColIndex) CalculateProbes() error
func (*VectorColIndex) CreateIndex ¶
func (vci *VectorColIndex) CreateIndex(_ context.Context, force bool) error