Documentation ¶
Index ¶
- Variables
- func NewBadRequestError(message string) error
- func NewNotFoundError(resource string) error
- type AppState
- type BadRequestError
- type CreateDocumentCollectionRequest
- type CreateDocumentRequest
- type CreateSessionRequest
- type CreateUserRequest
- type DistanceFunction
- type DocEmbeddingTask
- type DocEmbeddingUpdate
- type Document
- type DocumentBase
- type DocumentCollection
- type DocumentCollectionCounts
- type DocumentCollectionResponse
- type DocumentResponse
- type DocumentSearchPayload
- type DocumentSearchResult
- type DocumentSearchResultPage
- type DocumentStore
- type EmbeddingModel
- type Entity
- type EntityMatch
- type EntityRequest
- type EntityRequestRecord
- type EntityResponse
- type EntityResponseRecord
- type Extractor
- type GetDocumentListRequest
- type GetDocumentRequest
- type IndexType
- type Intent
- type IntentCollection
- type IntentPromptTemplateData
- type IntentResponse
- type Memory
- type MemorySearchPayload
- type MemorySearchResult
- type MemoryStore
- type Message
- type MessageEmbedding
- type MessageEmbeddingCollection
- type MessageEvent
- type MessageListResponse
- type NotFoundError
- type SearchDocumentQuery
- type Session
- type SessionListResponse
- type SessionManager
- type Summary
- type SummaryListResponse
- type UpdateDocumentCollectionRequest
- type UpdateDocumentListRequest
- type UpdateDocumentRequest
- type UpdateSessionRequest
- type UpdateUserRequest
- type User
- type UserListResponse
- type UserStore
- type ZepLLM
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrBadRequest = errors.New("bad request")
View Source
var ErrNotFound = errors.New("not found")
Functions ¶
func NewBadRequestError ¶ added in v0.12.0
func NewNotFoundError ¶ added in v0.9.0
Types ¶
type AppState ¶
type AppState struct { LLMClient ZepLLM MemoryStore MemoryStore[any] DocumentStore DocumentStore[any] UserStore UserStore Config *config.Config }
AppState is a struct that holds the state of the application Use cmd.NewAppState to create a new instance
type BadRequestError ¶ added in v0.12.0
type BadRequestError struct {
Message string
}
func (*BadRequestError) Error ¶ added in v0.12.0
func (e *BadRequestError) Error() string
func (*BadRequestError) Unwrap ¶ added in v0.12.0
func (e *BadRequestError) Unwrap() error
type CreateDocumentCollectionRequest ¶ added in v0.9.0
type CreateDocumentCollectionRequest struct { Name string `json:"name" validate:"required,alphanum,min=3,max=40"` Description string `json:"description" validate:"omitempty,max=1000"` Metadata map[string]interface{} `json:"metadata,omitempty"` EmbeddingDimensions int `json:"embedding_dimensions" validate:"required,numeric,min=8,max=2000"` // these needs to be pointers so that we can distinguish between false and unset when validating IsAutoEmbedded *bool `json:"is_auto_embedded" validate:"required,boolean"` }
type CreateDocumentRequest ¶ added in v0.9.0
type CreateDocumentRequest struct { DocumentID string `json:"document_id,omitempty" validate:"omitempty,printascii,max=100"` Content string `json:"content,omitempty" validate:"required_without=Embedding,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` Embedding []float32 `json:"embedding,omitempty" validate:"required_without=Content,omitempty"` }
type CreateSessionRequest ¶ added in v0.11.0
type CreateUserRequest ¶ added in v0.11.0
type DistanceFunction ¶ added in v0.13.0
type DistanceFunction string
type DocEmbeddingTask ¶ added in v0.9.0
type DocEmbeddingUpdate ¶ added in v0.9.0
type Document ¶ added in v0.9.0
type Document struct { DocumentBase Embedding []float32 `bun:"type:vector,nullzero" json:"embedding,omitempty"` }
type DocumentBase ¶ added in v0.9.0
type DocumentBase struct { UUID uuid.UUID `bun:",pk,type:uuid,default:gen_random_uuid()"` CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` UpdatedAt time.Time `bun:"type:timestamptz,nullzero,default:current_timestamp"` DeletedAt time.Time `bun:"type:timestamptz,soft_delete,nullzero"` DocumentID string `bun:",unique,nullzero"` Content string `bun:",nullzero"` Metadata map[string]interface{} `bun:"type:jsonb,nullzero,json_use_number"` IsEmbedded bool `bun:",nullzero"` }
type DocumentCollection ¶ added in v0.6.5
type DocumentCollection struct { UUID uuid.UUID `bun:",pk,type:uuid,default:gen_random_uuid()" yaml:"uuid"` CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp" yaml:"created_at"` UpdatedAt time.Time `bun:"type:timestamptz,nullzero,default:current_timestamp" yaml:"updated_at"` Name string `bun:",notnull,unique" yaml:"name"` Description string `bun:",notnull" yaml:"description"` Metadata map[string]interface{} `bun:"type:jsonb,nullzero,json_use_number" yaml:"metadata"` TableName string `bun:",notnull" yaml:"table_name"` EmbeddingModelName string `bun:",notnull" yaml:"embedding_model_name"` EmbeddingDimensions int `bun:",notnull" yaml:"embedding_dimensions"` IsAutoEmbedded bool `bun:",notnull" yaml:"is_auto_embedded"` // Is the collection automatically embedded by Zep? DistanceFunction DistanceFunction `bun:",notnull" yaml:"distance_function"` // Distance function to use for index IsNormalized bool `bun:",notnull" yaml:"is_normalized"` // Are the embeddings normalized? IsIndexed bool `bun:",notnull" yaml:"is_indexed"` // Has an index been created on the collection table? IndexType IndexType `bun:",notnull" yaml:"index_type"` // Type of index to use ListCount int `bun:",notnull" yaml:"list_count"` // Number of lists in the collection index ProbeCount int `bun:",notnull" yaml:"probe_count"` // Number of probes to use when searching the index *DocumentCollectionCounts ` yaml:"document_collection_counts,inline"` }
type DocumentCollectionCounts ¶ added in v0.9.0
type DocumentCollectionCounts struct { DocumentCount int `bun:"document_count" json:"document_count" yaml:"document_count,omitempty"` // Number of documents in the collection DocumentEmbeddedCount int `bun:"document_embedded_count" json:"document_embedded_count" yaml:"document_embedded_count,omitempty"` // Number of documents with embeddings }
type DocumentCollectionResponse ¶ added in v0.9.0
type DocumentCollectionResponse struct { UUID uuid.UUID `json:"uuid"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Name string `json:"name"` Description string `json:"description"` Metadata map[string]interface{} `json:"metadata,omitempty"` EmbeddingModelName string `json:"embedding_model_name,omitempty"` EmbeddingDimensions int `json:"embedding_dimensions"` IsAutoEmbedded bool `json:"is_auto_embedded"` IsNormalized bool `json:"is_normalized"` IsIndexed bool `json:"is_indexed"` *DocumentCollectionCounts }
type DocumentResponse ¶ added in v0.9.0
type DocumentResponse struct { UUID uuid.UUID `json:"uuid"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DocumentID string `json:"document_id"` Content string `json:"content"` Metadata map[string]interface{} `json:"metadata,omitempty"` Embedding []float32 `json:"embedding"` IsEmbedded bool `json:"is_embedded"` }
type DocumentSearchPayload ¶ added in v0.9.0
type DocumentSearchResult ¶ added in v0.9.0
type DocumentSearchResult struct { *DocumentResponse Score float64 `json:"score"` }
type DocumentSearchResultPage ¶ added in v0.9.0
type DocumentSearchResultPage struct { Results []DocumentSearchResult `json:"results"` QueryVector []float32 `json:"query_vector"` ResultCount int `json:"result_count"` TotalPages int `json:"total_pages"` CurrentPage int `json:"current_page"` }
type DocumentStore ¶ added in v0.9.0
type DocumentStore[T any] interface { // CreateCollection creates a new DocumentCollection. // If a collection with the same name already exists, it will be overwritten. CreateCollection( ctx context.Context, collection DocumentCollection, ) error UpdateCollection( ctx context.Context, collection DocumentCollection, ) error // GetCollection retrieves a DocumentCollection by name. GetCollection( ctx context.Context, collectionName string, ) (DocumentCollection, error) // GetCollectionList retrieves the list of DocumentCollection. GetCollectionList( ctx context.Context, ) ([]DocumentCollection, error) // DeleteCollection deletes a DocumentCollection by name. DeleteCollection( ctx context.Context, collectionName string, ) error // CreateDocuments creates a batch of Documents. CreateDocuments( ctx context.Context, collectionName string, documents []Document, ) ([]uuid.UUID, error) // UpdateDocuments updates a batch of Documents. // The provided Document UUIDs must match existing documents. UpdateDocuments( ctx context.Context, collectionName string, documents []Document, ) error // GetDocuments retrieves a Document by UUID. GetDocuments( ctx context.Context, collectionName string, uuids []uuid.UUID, DocumentID []string, ) ([]Document, error) // DeleteDocuments deletes a Document by UUID. DeleteDocuments( ctx context.Context, collectionName string, documentUUIDs []uuid.UUID, ) error // SearchCollection retrieves a collection of DocumentSearchResultPage based on the provided search query. // It accepts an optional limit for the total number of results, as well as parameters for pagination: pageNumber and pageSize. // Parameters: // - limit: Defines the maximum number of results returned. If it's 0, all the results will be returned. // - pageNumber: Specifies the current page number in the pagination scheme. // - pageSize: Determines the number of results per page. If it's -1, all results are returned on a single page. // The mmr parameter is used to enable/disable the MMR algorithm for search results. // The function will return the results in pages as determined by pageSize. SearchCollection( ctx context.Context, query *DocumentSearchPayload, limit int, withMMR bool, pageNumber int, pageSize int, ) (*DocumentSearchResultPage, error) // CreateCollectionIndex creates an index on the collection. Manually calling this function will drop and // recreate the index, if it exists. // force: If true, the index will be created even if there are too few documents in the collection. CreateCollectionIndex(ctx context.Context, collectionName string, force bool) error // OnStart is called when the application starts. This is a good place to initialize any resources or configs that // are required by the MemoryStore implementation. OnStart(ctx context.Context) error // Shutdown is called when the application is shutting down. This is a good place to clean up any resources or configs Shutdown(ctx context.Context) error // GetClient returns the underlying storage client GetClient() any }
DocumentStore interface
type EmbeddingModel ¶ added in v0.6.5
type Entity ¶ added in v0.5.0
type Entity struct { Name string `json:"name"` Label string `json:"label"` Matches []EntityMatch `json:"matches"` }
type EntityMatch ¶ added in v0.5.0
type EntityRequest ¶ added in v0.5.0
type EntityRequest struct {
Texts []EntityRequestRecord `json:"texts"`
}
type EntityRequestRecord ¶ added in v0.5.0
type EntityResponse ¶ added in v0.5.0
type EntityResponse struct {
Texts []EntityResponseRecord `json:"texts"`
}
type EntityResponseRecord ¶ added in v0.5.0
type Extractor ¶
type Extractor interface { Extract( ctx context.Context, appState *AppState, messageEvents *MessageEvent, ) error Notify(ctx context.Context, appState *AppState, messageEvents *MessageEvent) error }
Extractor is an interface that defines the methods that must be implemented by an Extractor
type GetDocumentListRequest ¶ added in v0.9.0
type GetDocumentRequest ¶ added in v0.9.0
type IntentCollection ¶ added in v0.7.0
type IntentPromptTemplateData ¶ added in v0.7.0
type IntentPromptTemplateData struct {
Input string
}
type IntentResponse ¶ added in v0.7.0
type IntentResponse struct {
Intent string `json:"intent"`
}
type MemorySearchPayload ¶ added in v0.6.0
type MemorySearchResult ¶ added in v0.6.0
type MemoryStore ¶
type MemoryStore[T any] interface { // 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 GetMemory(ctx context.Context, appState *AppState, sessionID string, lastNMessages int) (*Memory, error) // GetMessageList retrieves a list of messages for a given sessionID. Paginated by cursor and limit. GetMessageList(ctx context.Context, appState *AppState, sessionID string, pageNumber int, pageSize int, ) (*MessageListResponse, error) // GetSummary retrieves the most recent Summary for a given sessionID. The Summary return includes the UUID of the // SummaryPoint, which the most recent Message in the collection of messages that was used to generate the Summary. GetSummary(ctx context.Context, appState *AppState, sessionID string) (*Summary, error) // GetSummaryList retrieves a list of Summary for a given sessionID. Paginated by cursor and limit. GetSummaryList(ctx context.Context, appState *AppState, sessionID string, pageNumber int, pageSize int, ) (*SummaryListResponse, error) // PutMemory stores a Memory for a given sessionID. If the SessionID doesn't exist, a new one is created. PutMemory(ctx context.Context, appState *AppState, sessionID string, memoryMessages *Memory, skipNotify bool) error // skipNotify is used to prevent loops when calling NotifyExtractors. // PutSummary stores a new Summary for a given sessionID. PutSummary(ctx context.Context, appState *AppState, sessionID string, summary *Summary) error // PutMessageMetadata creates, updates, or deletes metadata for a given message, and does not // update the message itself. // isPrivileged indicates whether the caller is privileged to add or update system metadata. PutMessageMetadata(ctx context.Context, appState *AppState, sessionID string, messages []Message, isPrivileged bool) error // PutMessageVectors stores a collection of MessageEmbedding for a given sessionID. PutMessageVectors(ctx context.Context, appState *AppState, sessionID string, embeddings []MessageEmbedding) error // GetMessageVectors retrieves a collection of MessageEmbedding for a given sessionID. GetMessageVectors(ctx context.Context, appState *AppState, sessionID string) ([]MessageEmbedding, error) // SearchMemory retrieves a collection of SearchResults for a given sessionID and query. Currently, The // MemorySearchResult structure can include both Messages and Summaries. Currently, we only search Messages. SearchMemory( ctx context.Context, appState *AppState, sessionID string, query *MemorySearchPayload, limit int) ([]MemorySearchResult, error) // DeleteSession deletes all records for a given sessionID. This is a soft delete. Related Messages // and MessageEmbeddings are also soft deleted. DeleteSession(ctx context.Context, sessionID string) error // GetSession retrieves a Session for a given sessionID. GetSession( ctx context.Context, appState *AppState, sessionID string, ) (*Session, error) // CreateSession creates a new Session for a given sessionID. CreateSession( ctx context.Context, appState *AppState, session *CreateSessionRequest, ) (*Session, error) // UpdateSession updates a Session for a given sessionID. Omly the metadata is updated. UpdateSession( ctx context.Context, appState *AppState, session *UpdateSessionRequest, ) (*Session, error) // ListSessions returns a list of all Sessions, paginated by cursor and limit. ListSessions( ctx context.Context, appState *AppState, cursor int64, limit int, ) ([]*Session, error) // ListSessionsOrdered returns an ordered list of all Sessions, paginated by pageNumber and pageSize, and // the total count of all sessions. // orderedBy is the column to order by. asc is a boolean indicating whether to order ascending or descending. ListSessionsOrdered( ctx context.Context, appState *AppState, pageNumber int, pageSize int, orderedBy string, asc bool, ) (*SessionListResponse, error) // Attach is used by Extractors to register themselves with the MemoryStore. This allows the MemoryStore to notify // the Extractors when new occur. Attach(observer Extractor) // NotifyExtractors notifies all registered Extractors of a new MessageEvent. NotifyExtractors( ctx context.Context, appState *AppState, eventData *MessageEvent, ) // PurgeDeleted hard deletes all deleted data in the MemoryStore. PurgeDeleted(ctx context.Context) error // Close is called when the application is shutting down. This is a good place to clean up any resources used by // the MemoryStore implementation. Close() error }
MemoryStore interface TODO: This needs to be broken up into smaller interfaces.
type MessageEmbedding ¶ added in v0.9.0
type MessageEmbeddingCollection ¶ added in v0.9.0
type MessageEmbeddingCollection struct { UUID uuid.UUID `json:"uuid,omitempty"` Name string `json:"name,omitempty"` Embeddings []MessageEmbedding `json:"documents"` }
type MessageEvent ¶
type MessageListResponse ¶ added in v0.12.0
type NotFoundError ¶ added in v0.9.0
type NotFoundError struct {
Resource string
}
func (*NotFoundError) Error ¶ added in v0.9.0
func (e *NotFoundError) Error() string
func (*NotFoundError) Unwrap ¶ added in v0.9.0
func (e *NotFoundError) Unwrap() error
type SearchDocumentQuery ¶ added in v0.9.0
type Session ¶
type Session struct { UUID uuid.UUID `json:"uuid"` ID int64 `json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"deleted_at"` SessionID string `json:"session_id"` Metadata map[string]interface{} `json:"metadata"` // Must be a pointer to allow for null values UserID *string `json:"user_id"` }
type SessionListResponse ¶ added in v0.12.0
type SessionManager ¶ added in v0.11.0
type SessionManager interface { Create(ctx context.Context, session *CreateSessionRequest) (*Session, error) Get(ctx context.Context, sessionID string) (*Session, error) Update(ctx context.Context, session *UpdateSessionRequest, isPrivileged bool) (*Session, error) Delete(ctx context.Context, sessionID string) error ListAll(ctx context.Context, cursor int64, limit int) ([]*Session, error) }
type Summary ¶
type Summary struct { UUID uuid.UUID `json:"uuid"` CreatedAt time.Time `json:"created_at"` Content string `json:"content"` SummaryPointUUID uuid.UUID `json:"recent_message_uuid"` // The most recent message UUID that was used to generate this summary Metadata map[string]interface{} `json:"metadata,omitempty"` TokenCount int `json:"token_count"` }
type SummaryListResponse ¶ added in v0.12.0
type UpdateDocumentCollectionRequest ¶ added in v0.9.0
type UpdateDocumentListRequest ¶ added in v0.9.0
type UpdateDocumentListRequest struct { UUID uuid.UUID `json:"uuid" validate:"required"` UpdateDocumentRequest }
type UpdateDocumentRequest ¶ added in v0.9.0
type UpdateSessionRequest ¶ added in v0.11.0
type UpdateUserRequest ¶ added in v0.11.0
type User ¶ added in v0.11.0
type User struct { UUID uuid.UUID `json:"uuid"` ID int64 `json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"deleted_at"` UserID string `json:"user_id"` Email string `json:"email,omitempty"` FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` }
type UserListResponse ¶ added in v0.12.0
type UserStore ¶ added in v0.11.0
type UserStore interface { Create(ctx context.Context, user *CreateUserRequest) (*User, error) Get(ctx context.Context, userID string) (*User, error) Update(ctx context.Context, user *UpdateUserRequest, isPrivileged bool) (*User, error) Delete(ctx context.Context, userID string) error GetSessions(ctx context.Context, userID string) ([]*Session, error) ListAll(ctx context.Context, cursor int64, limit int) ([]*User, error) ListAllOrdered(ctx context.Context, pageNumber int, pageSize int, orderBy string, asc bool, ) (*UserListResponse, error) }
type ZepLLM ¶ added in v0.10.0
type ZepLLM interface { // Call runs the LLM chat completion against the prompt // this version of Call uses the chat endpoint of an LLM, but // we pass in a simple string prompt Call( ctx context.Context, prompt string, options ...llms.CallOption, ) (string, error) // EmbedTexts embeds the given texts EmbedTexts(ctx context.Context, texts []string) ([][]float32, error) // GetTokenCount returns the number of tokens in the given text GetTokenCount(text string) (int, error) // Init initializes the LLM Init(ctx context.Context, cfg *config.Config) error }
Click to show internal directories.
Click to hide internal directories.