Documentation
¶
Overview ¶
Package store provides PostgreSQL-backed data access for Creel.
Index ¶
- func EnsureSchema(ctx context.Context, baseURL, schema string) error
- func NewPool(ctx context.Context, postgresURL string) (*pgxpool.Pool, error)
- func RunMigrations(postgresURL, migrationsPath string) error
- type APIKeyConfig
- type APIKeyConfigStore
- func (s *APIKeyConfigStore) Create(ctx context.Context, name, provider string, apiKey []byte, isDefault bool) (*APIKeyConfig, error)
- func (s *APIKeyConfigStore) Delete(ctx context.Context, id string) error
- func (s *APIKeyConfigStore) Get(ctx context.Context, id string) (*APIKeyConfig, error)
- func (s *APIKeyConfigStore) GetDecrypted(ctx context.Context, id string) ([]byte, error)
- func (s *APIKeyConfigStore) List(ctx context.Context) ([]APIKeyConfig, error)
- func (s *APIKeyConfigStore) SetDefault(ctx context.Context, id string) (*APIKeyConfig, error)
- func (s *APIKeyConfigStore) Update(ctx context.Context, id, name, provider string, apiKey []byte) (*APIKeyConfig, error)
- type Chunk
- type ChunkStore
- func (s *ChunkStore) ChunkIDsByTopics(ctx context.Context, topicIDs []string, excludeDocIDs []string) ([]string, error)
- func (s *ChunkStore) Create(ctx context.Context, documentID, content string, sequence int, ...) (*Chunk, error)
- func (s *ChunkStore) Delete(ctx context.Context, id string) error
- func (s *ChunkStore) DocumentTopicID(ctx context.Context, documentID string) (string, error)
- func (s *ChunkStore) DocumentTopicIDs(ctx context.Context, docIDs []string) (map[string]string, error)
- func (s *ChunkStore) Get(ctx context.Context, id string) (*Chunk, error)
- func (s *ChunkStore) GetMultiple(ctx context.Context, ids []string) (map[string]*Chunk, error)
- func (s *ChunkStore) ListByDocument(ctx context.Context, documentID string, lastN int, since time.Time) ([]*Chunk, error)
- func (s *ChunkStore) SetEmbeddingID(ctx context.Context, chunkID, embeddingID string) error
- type DBTX
- type Document
- type DocumentStore
- func (s *DocumentStore) Create(ctx context.Context, topicID, slug, name, docType string, ...) (*Document, error)
- func (s *DocumentStore) Delete(ctx context.Context, id string) error
- func (s *DocumentStore) Get(ctx context.Context, id string) (*Document, error)
- func (s *DocumentStore) ListByTopic(ctx context.Context, topicID string) ([]Document, error)
- func (s *DocumentStore) TopicIDForDocument(ctx context.Context, docID string) (string, error)
- func (s *DocumentStore) Update(ctx context.Context, id, name, docType string, metadata map[string]any) (*Document, error)
- type EmbeddingConfig
- type EmbeddingConfigStore
- func (s *EmbeddingConfigStore) Create(ctx context.Context, name, provider, model string, dimensions int, ...) (*EmbeddingConfig, error)
- func (s *EmbeddingConfigStore) Delete(ctx context.Context, id string) error
- func (s *EmbeddingConfigStore) Get(ctx context.Context, id string) (*EmbeddingConfig, error)
- func (s *EmbeddingConfigStore) GetDefault(ctx context.Context) (*EmbeddingConfig, error)
- func (s *EmbeddingConfigStore) List(ctx context.Context) ([]EmbeddingConfig, error)
- func (s *EmbeddingConfigStore) SetDefault(ctx context.Context, id string) (*EmbeddingConfig, error)
- func (s *EmbeddingConfigStore) Update(ctx context.Context, id, name, apiKeyConfigID string) (*EmbeddingConfig, error)
- type ExtractionPromptConfig
- type ExtractionPromptConfigStore
- func (s *ExtractionPromptConfigStore) Create(ctx context.Context, name, prompt, description string, isDefault bool) (*ExtractionPromptConfig, error)
- func (s *ExtractionPromptConfigStore) Delete(ctx context.Context, id string) error
- func (s *ExtractionPromptConfigStore) Get(ctx context.Context, id string) (*ExtractionPromptConfig, error)
- func (s *ExtractionPromptConfigStore) GetDefault(ctx context.Context) (*ExtractionPromptConfig, error)
- func (s *ExtractionPromptConfigStore) List(ctx context.Context) ([]ExtractionPromptConfig, error)
- func (s *ExtractionPromptConfigStore) SetDefault(ctx context.Context, id string) (*ExtractionPromptConfig, error)
- func (s *ExtractionPromptConfigStore) Update(ctx context.Context, id, name, prompt, description string) (*ExtractionPromptConfig, error)
- type GrantStore
- type LLMConfig
- type LLMConfigStore
- func (s *LLMConfigStore) Create(ctx context.Context, name, provider, model string, params map[string]string, ...) (*LLMConfig, error)
- func (s *LLMConfigStore) Delete(ctx context.Context, id string) error
- func (s *LLMConfigStore) Get(ctx context.Context, id string) (*LLMConfig, error)
- func (s *LLMConfigStore) GetDefault(ctx context.Context) (*LLMConfig, error)
- func (s *LLMConfigStore) List(ctx context.Context) ([]LLMConfig, error)
- func (s *LLMConfigStore) SetDefault(ctx context.Context, id string) (*LLMConfig, error)
- func (s *LLMConfigStore) Update(ctx context.Context, id, name, provider, model string, ...) (*LLMConfig, error)
- type SystemAccount
- type SystemAccountKey
- type SystemAccountStore
- func (s *SystemAccountStore) Create(ctx context.Context, name, description string) (*SystemAccount, string, error)
- func (s *SystemAccountStore) Delete(ctx context.Context, id string) error
- func (s *SystemAccountStore) List(ctx context.Context) ([]SystemAccount, error)
- func (s *SystemAccountStore) LookupKeyHash(ctx context.Context, hash string) (*auth.Principal, error)
- func (s *SystemAccountStore) RevokeKey(ctx context.Context, accountID string) error
- func (s *SystemAccountStore) RotateKey(ctx context.Context, accountID string, gracePeriod time.Duration) (string, error)
- type Topic
- type TopicGrant
- type TopicStore
- func (s *TopicStore) Create(ctx context.Context, slug, name, description, owner string, ...) (*Topic, error)
- func (s *TopicStore) Delete(ctx context.Context, id string) error
- func (s *TopicStore) Get(ctx context.Context, id string) (*Topic, error)
- func (s *TopicStore) Grant(ctx context.Context, topicID, principal, permission, grantedBy string) (*TopicGrant, error)
- func (s *TopicStore) ListForPrincipals(ctx context.Context, principals []string) ([]Topic, error)
- func (s *TopicStore) ListGrants(ctx context.Context, topicID string) ([]TopicGrant, error)
- func (s *TopicStore) Revoke(ctx context.Context, topicID, principal string) error
- func (s *TopicStore) Update(ctx context.Context, id, name, description string, ...) (*Topic, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureSchema ¶ added in v0.1.4
EnsureSchema creates the given schema if it does not already exist. It opens a one-shot connection to baseURL (which should not include search_path), validates the schema name, runs CREATE SCHEMA IF NOT EXISTS, and closes the connection.
func RunMigrations ¶
RunMigrations applies all pending database migrations.
Types ¶
type APIKeyConfig ¶ added in v0.1.5
type APIKeyConfig struct {
ID string
Name string
Provider string
IsDefault bool
CreatedAt time.Time
UpdatedAt time.Time
}
APIKeyConfig represents a stored API key configuration.
type APIKeyConfigStore ¶ added in v0.1.5
type APIKeyConfigStore struct {
// contains filtered or unexported fields
}
APIKeyConfigStore handles API key configuration persistence.
func NewAPIKeyConfigStore ¶ added in v0.1.5
func NewAPIKeyConfigStore(pool DBTX, encryptor *crypto.Encryptor) *APIKeyConfigStore
NewAPIKeyConfigStore creates a new API key config store.
func (*APIKeyConfigStore) Create ¶ added in v0.1.5
func (s *APIKeyConfigStore) Create(ctx context.Context, name, provider string, apiKey []byte, isDefault bool) (*APIKeyConfig, error)
Create inserts a new API key config with the key encrypted at rest.
func (*APIKeyConfigStore) Delete ¶ added in v0.1.5
func (s *APIKeyConfigStore) Delete(ctx context.Context, id string) error
Delete removes an API key config by ID.
func (*APIKeyConfigStore) Get ¶ added in v0.1.5
func (s *APIKeyConfigStore) Get(ctx context.Context, id string) (*APIKeyConfig, error)
Get retrieves an API key config by ID (without the decrypted key).
func (*APIKeyConfigStore) GetDecrypted ¶ added in v0.1.5
GetDecrypted retrieves the decrypted API key for server-side use.
func (*APIKeyConfigStore) List ¶ added in v0.1.5
func (s *APIKeyConfigStore) List(ctx context.Context) ([]APIKeyConfig, error)
List returns all API key configs (without decrypted keys).
func (*APIKeyConfigStore) SetDefault ¶ added in v0.1.5
func (s *APIKeyConfigStore) SetDefault(ctx context.Context, id string) (*APIKeyConfig, error)
SetDefault marks the given config as the default, clearing any previous default.
func (*APIKeyConfigStore) Update ¶ added in v0.1.5
func (s *APIKeyConfigStore) Update(ctx context.Context, id, name, provider string, apiKey []byte) (*APIKeyConfig, error)
Update modifies an API key config. If apiKey is non-nil, the key is re-encrypted.
type Chunk ¶
type Chunk struct {
ID string
DocumentID string
Sequence int
Content string
EmbeddingID *string
Status string
CompactedBy *string
Metadata map[string]any
CreatedAt time.Time
}
Chunk represents a stored chunk.
type ChunkStore ¶
type ChunkStore struct {
// contains filtered or unexported fields
}
ChunkStore handles chunk persistence.
func NewChunkStore ¶
func NewChunkStore(pool DBTX) *ChunkStore
NewChunkStore creates a new chunk store.
func (*ChunkStore) ChunkIDsByTopics ¶
func (s *ChunkStore) ChunkIDsByTopics(ctx context.Context, topicIDs []string, excludeDocIDs []string) ([]string, error)
ChunkIDsByTopics returns all active chunk IDs belonging to the given topics.
func (*ChunkStore) Create ¶
func (s *ChunkStore) Create(ctx context.Context, documentID, content string, sequence int, metadata map[string]any) (*Chunk, error)
Create inserts a new chunk and returns it.
func (*ChunkStore) Delete ¶
func (s *ChunkStore) Delete(ctx context.Context, id string) error
Delete removes a chunk.
func (*ChunkStore) DocumentTopicID ¶
DocumentTopicID returns the topic ID for a chunk's document.
func (*ChunkStore) DocumentTopicIDs ¶
func (s *ChunkStore) DocumentTopicIDs(ctx context.Context, docIDs []string) (map[string]string, error)
DocumentTopicIDs returns a mapping of document ID to topic ID for the given documents.
func (*ChunkStore) GetMultiple ¶
GetMultiple retrieves multiple chunks by ID in a single query.
func (*ChunkStore) ListByDocument ¶ added in v0.1.4
func (s *ChunkStore) ListByDocument(ctx context.Context, documentID string, lastN int, since time.Time) ([]*Chunk, error)
ListByDocument returns active chunks for a document in sequence order. If lastN > 0, returns only the last N chunks (ordered ascending by sequence). If since is non-zero, only returns chunks created at or after that time.
func (*ChunkStore) SetEmbeddingID ¶
func (s *ChunkStore) SetEmbeddingID(ctx context.Context, chunkID, embeddingID string) error
SetEmbeddingID updates the embedding_id for a chunk.
type DBTX ¶
type DBTX interface {
Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
Begin(ctx context.Context) (pgx.Tx, error)
}
DBTX is the interface satisfied by *pgxpool.Pool and *pgx.Tx. All stores accept this instead of a concrete pool so that a QueryCounter (or transaction) can be substituted in tests.
type Document ¶
type Document struct {
ID string
TopicID string
Slug string
Name string
DocType string
Metadata map[string]any
CreatedAt time.Time
UpdatedAt time.Time
}
Document represents a stored document.
type DocumentStore ¶
type DocumentStore struct {
// contains filtered or unexported fields
}
DocumentStore handles document persistence.
func NewDocumentStore ¶
func NewDocumentStore(pool DBTX) *DocumentStore
NewDocumentStore creates a new document store.
func (*DocumentStore) Create ¶
func (s *DocumentStore) Create(ctx context.Context, topicID, slug, name, docType string, metadata map[string]any) (*Document, error)
Create inserts a new document.
func (*DocumentStore) Delete ¶
func (s *DocumentStore) Delete(ctx context.Context, id string) error
Delete removes a document and cascades to chunks.
func (*DocumentStore) ListByTopic ¶
ListByTopic returns documents in a topic.
func (*DocumentStore) TopicIDForDocument ¶
TopicIDForDocument returns the topic ID that owns the given document.
type EmbeddingConfig ¶ added in v0.1.5
type EmbeddingConfig struct {
ID string
Name string
Provider string
Model string
Dimensions int
APIKeyConfigID string
IsDefault bool
CreatedAt time.Time
UpdatedAt time.Time
}
EmbeddingConfig represents a stored embedding configuration.
type EmbeddingConfigStore ¶ added in v0.1.5
type EmbeddingConfigStore struct {
// contains filtered or unexported fields
}
EmbeddingConfigStore handles embedding configuration persistence.
func NewEmbeddingConfigStore ¶ added in v0.1.5
func NewEmbeddingConfigStore(pool DBTX) *EmbeddingConfigStore
NewEmbeddingConfigStore creates a new embedding config store.
func (*EmbeddingConfigStore) Create ¶ added in v0.1.5
func (s *EmbeddingConfigStore) Create(ctx context.Context, name, provider, model string, dimensions int, apiKeyConfigID string, isDefault bool) (*EmbeddingConfig, error)
Create inserts a new embedding config.
func (*EmbeddingConfigStore) Delete ¶ added in v0.1.5
func (s *EmbeddingConfigStore) Delete(ctx context.Context, id string) error
Delete removes an embedding config by ID.
func (*EmbeddingConfigStore) Get ¶ added in v0.1.5
func (s *EmbeddingConfigStore) Get(ctx context.Context, id string) (*EmbeddingConfig, error)
Get retrieves an embedding config by ID.
func (*EmbeddingConfigStore) GetDefault ¶ added in v0.1.5
func (s *EmbeddingConfigStore) GetDefault(ctx context.Context) (*EmbeddingConfig, error)
GetDefault returns the default embedding config, or nil if none is set.
func (*EmbeddingConfigStore) List ¶ added in v0.1.5
func (s *EmbeddingConfigStore) List(ctx context.Context) ([]EmbeddingConfig, error)
List returns all embedding configs.
func (*EmbeddingConfigStore) SetDefault ¶ added in v0.1.5
func (s *EmbeddingConfigStore) SetDefault(ctx context.Context, id string) (*EmbeddingConfig, error)
SetDefault marks the given config as the default, clearing any previous default.
func (*EmbeddingConfigStore) Update ¶ added in v0.1.5
func (s *EmbeddingConfigStore) Update(ctx context.Context, id, name, apiKeyConfigID string) (*EmbeddingConfig, error)
Update modifies an embedding config. Only name and api_key_config_id can be changed.
type ExtractionPromptConfig ¶ added in v0.1.5
type ExtractionPromptConfig struct {
ID string
Name string
Prompt string
Description string
IsDefault bool
CreatedAt time.Time
UpdatedAt time.Time
}
ExtractionPromptConfig represents a stored extraction prompt configuration.
type ExtractionPromptConfigStore ¶ added in v0.1.5
type ExtractionPromptConfigStore struct {
// contains filtered or unexported fields
}
ExtractionPromptConfigStore handles extraction prompt configuration persistence.
func NewExtractionPromptConfigStore ¶ added in v0.1.5
func NewExtractionPromptConfigStore(pool DBTX) *ExtractionPromptConfigStore
NewExtractionPromptConfigStore creates a new extraction prompt config store.
func (*ExtractionPromptConfigStore) Create ¶ added in v0.1.5
func (s *ExtractionPromptConfigStore) Create(ctx context.Context, name, prompt, description string, isDefault bool) (*ExtractionPromptConfig, error)
Create inserts a new extraction prompt config.
func (*ExtractionPromptConfigStore) Delete ¶ added in v0.1.5
func (s *ExtractionPromptConfigStore) Delete(ctx context.Context, id string) error
Delete removes an extraction prompt config by ID.
func (*ExtractionPromptConfigStore) Get ¶ added in v0.1.5
func (s *ExtractionPromptConfigStore) Get(ctx context.Context, id string) (*ExtractionPromptConfig, error)
Get retrieves an extraction prompt config by ID.
func (*ExtractionPromptConfigStore) GetDefault ¶ added in v0.1.5
func (s *ExtractionPromptConfigStore) GetDefault(ctx context.Context) (*ExtractionPromptConfig, error)
GetDefault returns the default extraction prompt config, or nil if none is set.
func (*ExtractionPromptConfigStore) List ¶ added in v0.1.5
func (s *ExtractionPromptConfigStore) List(ctx context.Context) ([]ExtractionPromptConfig, error)
List returns all extraction prompt configs.
func (*ExtractionPromptConfigStore) SetDefault ¶ added in v0.1.5
func (s *ExtractionPromptConfigStore) SetDefault(ctx context.Context, id string) (*ExtractionPromptConfig, error)
SetDefault marks the given config as the default, clearing any previous default.
func (*ExtractionPromptConfigStore) Update ¶ added in v0.1.5
func (s *ExtractionPromptConfigStore) Update(ctx context.Context, id, name, prompt, description string) (*ExtractionPromptConfig, error)
Update modifies an extraction prompt config.
type GrantStore ¶
type GrantStore struct {
// contains filtered or unexported fields
}
GrantStore provides access to topic grants and ownership from PostgreSQL.
func NewGrantStore ¶
func NewGrantStore(pool DBTX) *GrantStore
NewGrantStore creates a new grant store.
func (*GrantStore) GrantsForPrincipal ¶
func (s *GrantStore) GrantsForPrincipal(ctx context.Context, principals []string) ([]auth.Grant, error)
GrantsForPrincipal returns all grants matching any of the given principals.
func (*GrantStore) TopicOwner ¶
TopicOwner returns the owner of the given topic.
type LLMConfig ¶ added in v0.1.5
type LLMConfig struct {
ID string
Name string
Provider string
Model string
Parameters map[string]string
APIKeyConfigID string
IsDefault bool
CreatedAt time.Time
UpdatedAt time.Time
}
LLMConfig represents a stored LLM configuration.
type LLMConfigStore ¶ added in v0.1.5
type LLMConfigStore struct {
// contains filtered or unexported fields
}
LLMConfigStore handles LLM configuration persistence.
func NewLLMConfigStore ¶ added in v0.1.5
func NewLLMConfigStore(pool DBTX) *LLMConfigStore
NewLLMConfigStore creates a new LLM config store.
func (*LLMConfigStore) Create ¶ added in v0.1.5
func (s *LLMConfigStore) Create(ctx context.Context, name, provider, model string, params map[string]string, apiKeyConfigID string, isDefault bool) (*LLMConfig, error)
Create inserts a new LLM config.
func (*LLMConfigStore) Delete ¶ added in v0.1.5
func (s *LLMConfigStore) Delete(ctx context.Context, id string) error
Delete removes an LLM config by ID.
func (*LLMConfigStore) GetDefault ¶ added in v0.1.5
func (s *LLMConfigStore) GetDefault(ctx context.Context) (*LLMConfig, error)
GetDefault returns the default LLM config, or nil if none is set.
func (*LLMConfigStore) List ¶ added in v0.1.5
func (s *LLMConfigStore) List(ctx context.Context) ([]LLMConfig, error)
List returns all LLM configs.
func (*LLMConfigStore) SetDefault ¶ added in v0.1.5
SetDefault marks the given config as the default, clearing any previous default.
type SystemAccount ¶
type SystemAccount struct {
ID string
Name string
Description string
Principal string
CreatedAt time.Time
}
SystemAccount represents a stored system account.
type SystemAccountKey ¶
type SystemAccountKey struct {
ID string
AccountID string
KeyHash string
KeyPrefix string
Status string // "active", "grace_period", "revoked"
GraceExpiresAt *time.Time
CreatedAt time.Time
RevokedAt *time.Time
}
SystemAccountKey represents a stored API key.
type SystemAccountStore ¶
type SystemAccountStore struct {
// contains filtered or unexported fields
}
SystemAccountStore handles system account and key persistence.
func NewSystemAccountStore ¶
func NewSystemAccountStore(pool DBTX) *SystemAccountStore
NewSystemAccountStore creates a new store backed by the given pool.
func (*SystemAccountStore) Create ¶
func (s *SystemAccountStore) Create(ctx context.Context, name, description string) (*SystemAccount, string, error)
Create inserts a new system account and its initial key. Returns the account and the raw API key (shown once).
func (*SystemAccountStore) Delete ¶
func (s *SystemAccountStore) Delete(ctx context.Context, id string) error
Delete removes a system account and cascades to its keys.
func (*SystemAccountStore) List ¶
func (s *SystemAccountStore) List(ctx context.Context) ([]SystemAccount, error)
List returns all system accounts.
func (*SystemAccountStore) LookupKeyHash ¶
func (s *SystemAccountStore) LookupKeyHash(ctx context.Context, hash string) (*auth.Principal, error)
LookupKeyHash implements auth.KeyLookup. It resolves a key hash to a principal by checking active and grace-period keys.
func (*SystemAccountStore) RevokeKey ¶
func (s *SystemAccountStore) RevokeKey(ctx context.Context, accountID string) error
RevokeKey immediately revokes all active keys for the account.
func (*SystemAccountStore) RotateKey ¶
func (s *SystemAccountStore) RotateKey(ctx context.Context, accountID string, gracePeriod time.Duration) (string, error)
RotateKey generates a new key for the account. If gracePeriod > 0, old active keys enter grace period; otherwise they are revoked immediately.
type Topic ¶
type Topic struct {
ID string
Slug string
Name string
Description string
Owner string
CreatedAt time.Time
UpdatedAt time.Time
LLMConfigID *string
EmbeddingConfigID *string
ExtractionPromptConfigID *string
}
Topic represents a stored topic.
type TopicGrant ¶
type TopicGrant struct {
ID string
TopicID string
Principal string
Permission string
GrantedBy string
CreatedAt time.Time
}
TopicGrant represents a stored topic grant.
type TopicStore ¶
type TopicStore struct {
// contains filtered or unexported fields
}
TopicStore handles topic and grant persistence.
func NewTopicStore ¶
func NewTopicStore(pool DBTX) *TopicStore
NewTopicStore creates a new topic store.
func (*TopicStore) Create ¶
func (s *TopicStore) Create(ctx context.Context, slug, name, description, owner string, llmConfigID, embeddingConfigID, extractionPromptConfigID *string) (*Topic, error)
Create inserts a new topic with optional config IDs.
func (*TopicStore) Delete ¶
func (s *TopicStore) Delete(ctx context.Context, id string) error
Delete removes a topic and cascades to grants, documents, chunks.
func (*TopicStore) Grant ¶
func (s *TopicStore) Grant(ctx context.Context, topicID, principal, permission, grantedBy string) (*TopicGrant, error)
Grant creates or updates a topic grant.
func (*TopicStore) ListForPrincipals ¶
ListForPrincipals returns topics accessible to the given principal identities. If principals is nil, returns all topics (for system accounts).
func (*TopicStore) ListGrants ¶
func (s *TopicStore) ListGrants(ctx context.Context, topicID string) ([]TopicGrant, error)
ListGrants returns all grants for a topic.