ragstore

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

README

RAG Store

License

This project is dual-licensed under the following terms:

  • For non-commercial use, you may choose either the GNU Affero General Public License v3.0 (AGPLv3) or a separate commercial license (see below). You can find a copy of the AGPLv3 at: https://www.gnu.org/licenses/agpl-3.0.txt

  • For commercial use, a separate commercial license is required. Commercial licenses are available for various use cases. Please contact me via my contact page to obtain a commercial license.

Installation

go get github.com/dracory/ragstore

Documentation

Index

Constants

View Source
const COLUMN_CHUNK_INDEX = "chunk_index"
View Source
const COLUMN_CONTENT = "content"
View Source
const COLUMN_CREATED_AT = "created_at"
View Source
const COLUMN_DOCUMENT_ID = "document_id"
View Source
const COLUMN_EMBEDDING = "embedding"
View Source
const COLUMN_FILE_NAME = "file_name"
View Source
const COLUMN_ID = "id"
View Source
const COLUMN_MEMO = "memo"
View Source
const COLUMN_METAS = "metas"
View Source
const COLUMN_SOFT_DELETED_AT = "soft_deleted_at"
View Source
const COLUMN_STATUS = "status"
View Source
const COLUMN_TEXT = "text"
View Source
const COLUMN_UPDATED_AT = "updated_at"
View Source
const DOCUMENT_STATUS_ACTIVE = "active"
View Source
const DOCUMENT_STATUS_DELETED = "deleted"
View Source
const DOCUMENT_STATUS_INACTIVE = "inactive"
View Source
const MAX_DATETIME = "9999-12-31 23:59:59"

MAX_DATETIME is a far-future datetime used as the default soft-delete sentinel. Records with soft_deleted_at equal to this value are considered active.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	orm.ShortID
	DocumentIDField string    `json:"document_id" db:"document_id"`
	ChunkIndexField int       `json:"chunk_index" db:"chunk_index"`
	ContentField    string    `json:"content" db:"content"`
	EmbeddingField  string    `json:"embedding" db:"embedding"`
	CreatedAtTime   time.Time `json:"created_at" db:"created_at"`
	UpdatedAtTime   time.Time `json:"updated_at" db:"updated_at"`
	soft_delete.SoftDeletesMaxDate
}

func (*Chunk) ChunkIndex

func (o *Chunk) ChunkIndex() int

func (*Chunk) Content

func (o *Chunk) Content() string

func (*Chunk) CreatedAt

func (o *Chunk) CreatedAt() string

func (*Chunk) CreatedAtCarbon

func (o *Chunk) CreatedAtCarbon() *carbon.Carbon

func (*Chunk) CreatedAtStdTime added in v0.4.0

func (o *Chunk) CreatedAtStdTime() time.Time

CreatedAtStdTime returns the created_at as time.Time (for internal use)

func (*Chunk) DocumentID

func (o *Chunk) DocumentID() string

func (*Chunk) Embedding

func (o *Chunk) Embedding() []float32

func (*Chunk) EmbeddingFieldString added in v0.4.0

func (o *Chunk) EmbeddingFieldString() string

EmbeddingFieldString returns the embedding as a JSON string

func (*Chunk) EmbeddingFromString added in v0.4.0

func (o *Chunk) EmbeddingFromString(jsonStr string) []float32

func (*Chunk) ID added in v0.4.0

func (o *Chunk) ID() string

func (*Chunk) IsSoftDeleted

func (o *Chunk) IsSoftDeleted() bool

IsSoftDeleted checks if the chunk is soft deleted

func (*Chunk) SetChunkIndex

func (o *Chunk) SetChunkIndex(chunkIndex int) ChunkInterface

func (*Chunk) SetContent

func (o *Chunk) SetContent(content string) ChunkInterface

func (*Chunk) SetCreatedAt

func (o *Chunk) SetCreatedAt(createdAt string) ChunkInterface

func (*Chunk) SetDocumentID

func (o *Chunk) SetDocumentID(id string) ChunkInterface

func (*Chunk) SetEmbedding

func (o *Chunk) SetEmbedding(embedding []float32) ChunkInterface

func (*Chunk) SetEmbeddingFieldString added in v0.4.0

func (o *Chunk) SetEmbeddingFieldString(s string)

SetEmbeddingFieldString sets the embedding from a JSON string

func (*Chunk) SetID added in v0.4.0

func (o *Chunk) SetID(id string) ChunkInterface

func (*Chunk) SetSoftDeletedAt

func (o *Chunk) SetSoftDeletedAt(softDeletedAt string) ChunkInterface

func (*Chunk) SetUpdatedAt

func (o *Chunk) SetUpdatedAt(updatedAt string) ChunkInterface

func (*Chunk) SoftDeletedAt

func (o *Chunk) SoftDeletedAt() string

func (*Chunk) SoftDeletedAtCarbon

func (o *Chunk) SoftDeletedAtCarbon() *carbon.Carbon

func (*Chunk) UpdatedAt

func (o *Chunk) UpdatedAt() string

func (*Chunk) UpdatedAtCarbon

func (o *Chunk) UpdatedAtCarbon() *carbon.Carbon

func (*Chunk) UpdatedAtStdTime added in v0.4.0

func (o *Chunk) UpdatedAtStdTime() time.Time

UpdatedAtStdTime returns the updated_at as time.Time (for internal use)

type ChunkInterface

type ChunkInterface interface {
	IsSoftDeleted() bool

	ID() string
	SetID(id string) ChunkInterface

	DocumentID() string
	SetDocumentID(documentID string) ChunkInterface

	ChunkIndex() int
	SetChunkIndex(chunkIndex int) ChunkInterface

	Content() string
	SetContent(content string) ChunkInterface

	Embedding() []float32
	SetEmbedding(embedding []float32) ChunkInterface

	EmbeddingFieldString() string
	SetEmbeddingFieldString(s string)

	CreatedAt() string
	CreatedAtCarbon() *carbon.Carbon
	SetCreatedAt(createdAt string) ChunkInterface

	SoftDeletedAt() string
	SoftDeletedAtCarbon() *carbon.Carbon
	SetSoftDeletedAt(softDeletedAt string) ChunkInterface

	UpdatedAt() string
	UpdatedAtCarbon() *carbon.Carbon
	SetUpdatedAt(updatedAt string) ChunkInterface
}

func NewChunk

func NewChunk() ChunkInterface

func NewChunkFromExistingData

func NewChunkFromExistingData(data map[string]string) ChunkInterface

type ChunkQueryInterface

type ChunkQueryInterface interface {
	// Validation method
	Validate() error

	// Basic query methods
	IsCreatedAtGteSet() bool
	GetCreatedAtGte() string
	SetCreatedAtGte(createdAt string) ChunkQueryInterface

	IsCreatedAtLteSet() bool
	GetCreatedAtLte() string
	SetCreatedAtLte(createdAt string) ChunkQueryInterface

	IsIDSet() bool
	GetID() string
	SetID(id string) ChunkQueryInterface

	IsIDInSet() bool
	GetIDIn() []string
	SetIDIn(ids []string) ChunkQueryInterface

	IsIDNotInSet() bool
	GetIDNotIn() []string
	SetIDNotIn(ids []string) ChunkQueryInterface

	IsLimitSet() bool
	GetLimit() int
	SetLimit(limit int) ChunkQueryInterface

	IsDocumentIDSet() bool
	GetDocumentID() string
	SetDocumentID(documentID string) ChunkQueryInterface

	IsDocumentIDInSet() bool
	GetDocumentIDIn() []string
	SetDocumentIDIn(documentIDs []string) ChunkQueryInterface

	IsOffsetSet() bool
	GetOffset() int
	SetOffset(offset int) ChunkQueryInterface

	IsOrderBySet() bool
	GetOrderBy() string
	SetOrderBy(orderBy string) ChunkQueryInterface

	IsOrderDirectionSet() bool
	GetOrderDirection() string
	SetOrderDirection(orderDirection string) ChunkQueryInterface

	// Count related methods
	IsCountOnlySet() bool
	GetCountOnly() bool
	SetCountOnly(countOnly bool) ChunkQueryInterface

	// Soft delete related query methods
	IsWithSoftDeletedSet() bool
	GetWithSoftDeleted() bool
	SetWithSoftDeleted(withSoftDeleted bool) ChunkQueryInterface

	IsOnlySoftDeletedSet() bool
	GetOnlySoftDeleted() bool
	SetOnlySoftDeleted(onlySoftDeleted bool) ChunkQueryInterface

	IsUpdatedAtGteSet() bool
	GetUpdatedAtGte() string
	SetUpdatedAtGte(updatedAt string) ChunkQueryInterface

	IsUpdatedAtLteSet() bool
	GetUpdatedAtLte() string
	SetUpdatedAtLte(updatedAt string) ChunkQueryInterface
}

ChunkQueryInterface defines the interface for querying chunks

func ChunkQuery

func ChunkQuery() ChunkQueryInterface

ChunkQuery creates a new chunk query

type DocumentInterface

type DocumentInterface interface {
	IsActive() bool
	IsInactive() bool
	IsSoftDeleted() bool

	ID() string
	SetID(id string) DocumentInterface

	Status() string
	SetStatus(status string) DocumentInterface

	FileName() string
	SetFileName(fileName string) DocumentInterface

	Text() string
	SetText(text string) DocumentInterface

	Memo() string
	SetMemo(memo string) DocumentInterface

	Meta(key string) (string, error)
	SetMeta(key string, value string) error

	Metas() (map[string]string, error)
	SetMetas(metas map[string]string) error

	UpsertMetas(metas map[string]string) error

	CreatedAt() string
	CreatedAtCarbon() *carbon.Carbon
	SetCreatedAt(createdAt string) DocumentInterface

	SoftDeletedAt() string
	SoftDeletedAtCarbon() *carbon.Carbon
	SetSoftDeletedAt(softDeletedAt string) DocumentInterface

	UpdatedAt() string
	UpdatedAtCarbon() *carbon.Carbon
	SetUpdatedAt(updatedAt string) DocumentInterface
}

func NewDocument

func NewDocument() DocumentInterface

func NewDocumentFromExistingData

func NewDocumentFromExistingData(data map[string]string) DocumentInterface

type DocumentQueryInterface

type DocumentQueryInterface interface {
	// Validation method
	Validate() error

	// Count related methods
	IsCountOnlySet() bool
	GetCountOnly() bool
	SetCountOnly(countOnly bool) DocumentQueryInterface

	// Soft delete related query methods
	IsWithSoftDeletedSet() bool
	GetWithSoftDeleted() bool
	SetWithSoftDeleted(withSoftDeleted bool) DocumentQueryInterface

	IsOnlySoftDeletedSet() bool
	GetOnlySoftDeleted() bool
	SetOnlySoftDeleted(onlySoftDeleted bool) DocumentQueryInterface

	IsCreatedAtGteSet() bool
	GetCreatedAtGte() string
	SetCreatedAtGte(createdAt string) DocumentQueryInterface

	IsCreatedAtLteSet() bool
	GetCreatedAtLte() string
	SetCreatedAtLte(createdAt string) DocumentQueryInterface

	IsIDSet() bool
	GetID() string
	SetID(id string) DocumentQueryInterface

	IsIDInSet() bool
	GetIDIn() []string
	SetIDIn(ids []string) DocumentQueryInterface

	IsLimitSet() bool
	GetLimit() int
	SetLimit(limit int) DocumentQueryInterface

	IsOffsetSet() bool
	GetOffset() int
	SetOffset(offset int) DocumentQueryInterface

	IsOrderBySet() bool
	GetOrderBy() string
	SetOrderBy(orderBy string) DocumentQueryInterface

	IsOrderDirectionSet() bool
	GetOrderDirection() string
	SetOrderDirection(orderDirection string) DocumentQueryInterface

	IsStatusSet() bool
	GetStatus() string
	SetStatus(status string) DocumentQueryInterface
	SetStatusIn(statuses []string) DocumentQueryInterface

	IsStatusInSet() bool
	GetStatusIn() []string

	IsUpdatedAtGteSet() bool
	GetUpdatedAtGte() string
	SetUpdatedAtGte(updatedAt string) DocumentQueryInterface

	IsUpdatedAtLteSet() bool
	GetUpdatedAtLte() string
	SetUpdatedAtLte(updatedAt string) DocumentQueryInterface
}

DocumentQueryInterface defines the interface for querying chats

func DocumentQuery

func DocumentQuery() DocumentQueryInterface

DocumentQuery creates a new document query

type NewStoreOptions

type NewStoreOptions struct {
	TableDocumentName      string
	TableDocumentChunkName string
	DB                     *sql.DB
	AutomigrateEnabled     bool
	DebugEnabled           bool
	Logger                 *slog.Logger
}

NewStoreOptions define the options for creating a new block store

type StoreInterface

type StoreInterface interface {
	AutoMigrate() error
	EnableDebug(enabled bool)
	GetDB() *sql.DB
	GetLogger() *slog.Logger
	SetLogger(logger *slog.Logger)

	DocumentCount(options DocumentQueryInterface) (int64, error)
	DocumentCreate(document DocumentInterface) error
	DocumentDelete(document DocumentInterface) error
	DocumentDeleteByID(id string) error
	DocumentExists(id string) (bool, error)
	DocumentFindByID(id string) (DocumentInterface, error)
	DocumentList(options DocumentQueryInterface) ([]DocumentInterface, error)
	DocumentSoftDelete(document DocumentInterface) error
	DocumentSoftDeleteByID(id string) error
	DocumentUpdate(document DocumentInterface) error

	ChunkCount(options ChunkQueryInterface) (int64, error)
	ChunkCreate(chunk ChunkInterface) error
	ChunkDelete(chunk ChunkInterface) error
	ChunkDeleteByID(id string) error
	ChunkExists(id string) (bool, error)
	ChunkFindByID(id string) (ChunkInterface, error)
	ChunkList(options ChunkQueryInterface) ([]ChunkInterface, error)
	ChunkSoftDelete(chunk ChunkInterface) error
	ChunkSoftDeleteByID(id string) error
	ChunkUpdate(chunk ChunkInterface) error
}

func NewStore

func NewStore(opts NewStoreOptions) (StoreInterface, error)

NewStore creates a new block store

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL