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 MigrateMessageEmbeddingDims(ctx context.Context, db *bun.DB, dimensions int) error
- func NewPostgresConn(appState *models.AppState) (*bun.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
- func (*DocumentCollectionSchema) AfterCreateTable(ctx context.Context, query *bun.CreateTableQuery) error
- func (s *DocumentCollectionSchema) BeforeAppendModel(_ context.Context, query bun.Query) error
- func (s *DocumentCollectionSchema) BeforeCreateTable(_ context.Context, _ *bun.CreateTableQuery) error
- 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(ctx 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 MessageStoreSchema
- type MessageVectorStoreSchema
- func (*MessageVectorStoreSchema) AfterCreateTable(ctx context.Context, query *bun.CreateTableQuery) error
- func (s *MessageVectorStoreSchema) BeforeAppendModel(_ context.Context, query bun.Query) error
- func (s *MessageVectorStoreSchema) BeforeCreateTable(_ context.Context, _ *bun.CreateTableQuery) error
- type PostgresMemoryStore
- func (pms *PostgresMemoryStore) Close() error
- func (pms *PostgresMemoryStore) CreateSession(ctx context.Context, _ *models.AppState, session *models.CreateSessionRequest) (*models.Session, error)
- func (pms *PostgresMemoryStore) DeleteSession(ctx context.Context, sessionID string) error
- func (pms *PostgresMemoryStore) GetClient() *bun.DB
- func (pms *PostgresMemoryStore) GetMemory(ctx context.Context, appState *models.AppState, sessionID string, ...) (*models.Memory, error)
- func (pms *PostgresMemoryStore) GetMessageList(ctx context.Context, appState *models.AppState, sessionID string, ...) (*models.MessageListResponse, error)
- func (pms *PostgresMemoryStore) GetMessageVectors(ctx context.Context, _ *models.AppState, sessionID string) ([]models.MessageEmbedding, error)
- func (pms *PostgresMemoryStore) GetSession(ctx context.Context, _ *models.AppState, sessionID string) (*models.Session, error)
- func (pms *PostgresMemoryStore) GetSummary(ctx context.Context, _ *models.AppState, sessionID string) (*models.Summary, error)
- func (pms *PostgresMemoryStore) GetSummaryList(ctx context.Context, appState *models.AppState, sessionID string, ...) (*models.SummaryListResponse, error)
- func (pms *PostgresMemoryStore) ListSessions(ctx context.Context, _ *models.AppState, cursor int64, limit int) ([]*models.Session, error)
- func (pms *PostgresMemoryStore) ListSessionsOrdered(ctx context.Context, _ *models.AppState, pageNumber int, pageSize int, ...) (*models.SessionListResponse, error)
- func (pms *PostgresMemoryStore) OnStart(_ context.Context, appState *models.AppState) error
- func (pms *PostgresMemoryStore) PurgeDeleted(ctx context.Context) error
- func (pms *PostgresMemoryStore) PutMemory(ctx context.Context, appState *models.AppState, sessionID string, ...) error
- func (pms *PostgresMemoryStore) PutMessageMetadata(ctx context.Context, _ *models.AppState, sessionID string, ...) error
- func (pms *PostgresMemoryStore) PutMessageVectors(ctx context.Context, _ *models.AppState, sessionID string, ...) error
- func (pms *PostgresMemoryStore) PutSummary(ctx context.Context, _ *models.AppState, sessionID string, ...) error
- func (pms *PostgresMemoryStore) SearchMemory(ctx context.Context, appState *models.AppState, sessionID string, ...) ([]models.MemorySearchResult, error)
- func (pms *PostgresMemoryStore) UpdateSession(ctx context.Context, _ *models.AppState, session *models.UpdateSessionRequest) (*models.Session, 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 SummaryStoreSchema
- 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 DefaultDistanceFunction = "cosine"
DefaultDistanceFunction is the default distance function to use for indexing. Using cosine distance function by default in order to support both normalized and non-normalized embeddings. A future improvement would be to use a the inner product distance function for normalized embeddings.
const DefaultDocumentSearchLimit = 20
const DefaultEFSearch = 100
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 MigrateMessageEmbeddingDims ¶ added in v0.12.0
MigrateMessageEmbeddingDims drops the old embedding column and creates a new one with the correct dimensions.
Types ¶
type CustomRandSource ¶ added in v0.12.0
func (*CustomRandSource) Intn ¶ added in v0.12.0
func (s *CustomRandSource) Intn(n int) int
Override Intn method
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, withMMR bool, 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
func (*DocumentCollectionSchema) BeforeCreateTable ¶
func (s *DocumentCollectionSchema) BeforeCreateTable( _ context.Context, _ *bun.CreateTableQuery, ) error
type DocumentSchemaTemplate ¶
type DocumentSchemaTemplate struct { bun.BaseModel `bun:"table:document,alias:d"` models.DocumentBase }
DocumentSchemaTemplate represents the schema template for Document tables. MessageEmbedding 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] DocEmbeddingUpdateTaskCh chan []models.DocEmbeddingUpdate DocEmbeddingTaskCh chan<- []models.DocEmbeddingTask // contains filtered or unexported fields }
func NewDocumentStore ¶
func NewDocumentStore( appState *models.AppState, client *bun.DB, docEmbeddingUpdateTaskCh chan []models.DocEmbeddingUpdate, docEmbeddingTaskCh chan<- []models.DocEmbeddingTask, ) (*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, withMMR bool, 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 IndexStatus struct { Phase string `bun:"phase"` TuplesTotal int `bun:"tuples_total"` TuplesDone int `bun:"tuples_done"` }
func GetIndexStatus ¶ added in v0.13.0
GetIndexStatus queries for an index's status given an index name.
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
func (*MessageStoreSchema) BeforeCreateTable ¶
func (s *MessageStoreSchema) BeforeCreateTable( _ context.Context, _ *bun.CreateTableQuery, ) error
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
func (*MessageVectorStoreSchema) BeforeCreateTable ¶
func (s *MessageVectorStoreSchema) BeforeCreateTable( _ context.Context, _ *bun.CreateTableQuery, ) error
type PostgresMemoryStore ¶
type PostgresMemoryStore struct { store.BaseMemoryStore[*bun.DB] SessionStore *SessionDAO }
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) CreateSession ¶ added in v0.11.0
func (pms *PostgresMemoryStore) CreateSession( ctx context.Context, _ *models.AppState, session *models.CreateSessionRequest, ) (*models.Session, error)
CreateSession creates or updates a Session for a given sessionID.
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, appState *models.AppState, 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
func (*PostgresMemoryStore) GetMessageList ¶ added in v0.12.0
func (pms *PostgresMemoryStore) GetMessageList( ctx context.Context, appState *models.AppState, 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) GetMessageVectors ¶
func (pms *PostgresMemoryStore) GetMessageVectors(ctx context.Context, _ *models.AppState, sessionID string, ) ([]models.MessageEmbedding, error)
func (*PostgresMemoryStore) GetSession ¶
func (pms *PostgresMemoryStore) GetSession( ctx context.Context, _ *models.AppState, sessionID string, ) (*models.Session, error)
GetSession retrieves a Session for a given sessionID.
func (*PostgresMemoryStore) GetSummary ¶
func (*PostgresMemoryStore) GetSummaryList ¶ added in v0.12.0
func (*PostgresMemoryStore) ListSessions ¶ added in v0.11.0
func (pms *PostgresMemoryStore) ListSessions( ctx context.Context, _ *models.AppState, 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, _ *models.AppState, 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) PurgeDeleted ¶
func (pms *PostgresMemoryStore) PurgeDeleted(ctx context.Context) error
func (*PostgresMemoryStore) PutMessageMetadata ¶
func (*PostgresMemoryStore) PutMessageVectors ¶
func (pms *PostgresMemoryStore) PutMessageVectors(ctx context.Context, _ *models.AppState, sessionID string, embeddings []models.MessageEmbedding, ) error
func (*PostgresMemoryStore) PutSummary ¶
func (*PostgresMemoryStore) SearchMemory ¶
func (pms *PostgresMemoryStore) SearchMemory( ctx context.Context, appState *models.AppState, sessionID string, query *models.MemorySearchPayload, limit int, ) ([]models.MemorySearchResult, error)
func (*PostgresMemoryStore) UpdateSession ¶ added in v0.11.0
func (pms *PostgresMemoryStore) UpdateSession( ctx context.Context, _ *models.AppState, session *models.UpdateSessionRequest, ) (*models.Session, error)
UpdateSession creates or updates a Session for a given sessionID.
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 and message embeddings 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
func (*SessionSchema) BeforeCreateTable ¶
func (s *SessionSchema) BeforeCreateTable( _ context.Context, _ *bun.CreateTableQuery, ) error
BeforeCreateTable is a marker method to ensure uniform interface across all table models - used in table creation iterator
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
func (*SummaryStoreSchema) BeforeCreateTable ¶
func (s *SummaryStoreSchema) BeforeCreateTable( _ context.Context, _ *bun.CreateTableQuery, ) error
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
func (*UserSchema) BeforeCreateTable ¶ added in v0.11.0
func (u *UserSchema) BeforeCreateTable( _ context.Context, _ *bun.CreateTableQuery, ) error
BeforeCreateTable is a marker method to ensure uniform interface across all table models - used in table creation iterator
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