store

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CollectionStatusExpired represents the expired status.
	CollectionStatusExpired CollectionStatus = "expired"
	// CollectionStatusInProgress represents the in_progress status.
	CollectionStatusInProgress CollectionStatus = "in_progress"
	// CollectionStatusCompleted represents the completed status.
	CollectionStatusCompleted CollectionStatus = "completed"

	// ExpiresAfterAnchorLastActiveAt represents the anchor for the expiration time based on the last_active_at time.
	ExpiresAfterAnchorLastActiveAt ExpiresAfterAnchor = "last_active_at"
)
View Source
const (
	// FileStatusInProgress represents the in_progress status.
	FileStatusInProgress FileStatus = "in_progress"
	// FileStatusCompleted represents the completed status.
	FileStatusCompleted FileStatus = "completed"
	// FileStatusFailed represents the failed status.
	FileStatusFailed FileStatus = "failed"
	// FileStatusCancelled represents the cancelled status.
	FileStatusCancelled FileStatus = "cancelled"

	// LastErrorCodeNone represents no error.
	LastErrorCodeNone LastErrorCode = ""
	// LastErrorCodeServerError represents a server error.
	LastErrorCodeServerError LastErrorCode = "server_error"
	// LastErrorCodeRateLimitExceeded represents a rate limit exceeded error.
	LastErrorCodeRateLimitExceeded LastErrorCode = "rate_limit_exceeded"

	// ChunkingStrategyTypeAuto represents the auto chunking strategy.
	ChunkingStrategyTypeAuto ChunkingStrategyType = "auto"
	// ChunkingStrategyTypeStatic represents the static chunking strategy.
	ChunkingStrategyTypeStatic ChunkingStrategyType = "static"
)

Variables

View Source
var (
	// ErrConcurrentUpdate is returned when there is a concurrent update.
	ErrConcurrentUpdate = fmt.Errorf("store: concurrent update")
)

Functions

func CreateCollectionInTransaction

func CreateCollectionInTransaction(tx *gorm.DB, c *Collection) error

CreateCollectionInTransaction creates a new collection.

func CreateCollectionMetadataInTransaction

func CreateCollectionMetadataInTransaction(tx *gorm.DB, cm *CollectionMetadata) error

CreateCollectionMetadataInTransaction creates a new collection metadata.

func DeleteAllCollectionMetadatasByVectorStoreIDInTransaction

func DeleteAllCollectionMetadatasByVectorStoreIDInTransaction(tx *gorm.DB, vectorStoreID string) error

DeleteAllCollectionMetadatasByVectorStoreIDInTransaction deletes all metadata of the collection.

func DeleteAllFilesByVectorStoreIDInTransaction

func DeleteAllFilesByVectorStoreIDInTransaction(tx *gorm.DB, vectorStoreID string) error

DeleteAllFilesByVectorStoreIDInTransaction deletes all files of the collection.

func DeleteCollectionInTransaction

func DeleteCollectionInTransaction(tx *gorm.DB, projectID string, vectorStoreID string) error

DeleteCollectionInTransaction deletes the collection.

func DeleteCollectionMetadataInTransaction

func DeleteCollectionMetadataInTransaction(tx *gorm.DB, id uint) error

DeleteCollectionMetadataInTransaction deletes the metadata for the collection.

func UpdateCollectionInTransaction

func UpdateCollectionInTransaction(tx *gorm.DB, nc *Collection) error

UpdateCollectionInTransaction updates the collection.

func UpdateCollectionMetadataInTransaction

func UpdateCollectionMetadataInTransaction(tx *gorm.DB, cm *CollectionMetadata) error

UpdateCollectionMetadataInTransaction updates the metadata of a collection.

Types

type ChunkingStrategyType

type ChunkingStrategyType string

ChunkingStrategyType represents the type of chunking strategy.

type Collection

type Collection struct {
	gorm.Model

	TenantID       string
	OrganizationID string
	ProjectID      string `gorm:"uniqueIndex:idx_collection_project_id_name"`

	// VectorStoreID is the ID of the vector store that is externally visible in the API.
	// This is also used as the name of the Milvus collection.
	VectorStoreID string `gorm:"uniqueIndex"`

	// CollectionID is the ID of the Milvus collection.
	CollectionID int64 `gorm:"uniqueIndex"`

	Name string `gorm:"uniqueIndex:idx_collection_project_id_name"`

	// UsageBytes is the total number of bytes used by the files in the vector store.
	UsageBytes int64

	FileCountsInProgress int64
	FileCountsCompleted  int64
	FileCountsFailed     int64
	FileCountsCancelled  int64
	FileCountsTotal      int64

	// TODO(guangrui): Update status.
	Status CollectionStatus

	Anchor ExpiresAfterAnchor
	// ExpiresAfterDays is the number of days the anchor time for when the vector store will expire.
	ExpiresAfterDays int64
	// ExpiresAt is the Unix timestamp (in seconds) for when the vector store will expire.
	ExpiresAt int64

	// LastActiveAt is the Unix timestamp (in seconds) for when the vector store was last active.
	LastActiveAt int64

	EmbeddingModel      string
	EmbeddingDimensions int

	Version int
}

Collection represents a collection.

type CollectionMetadata

type CollectionMetadata struct {
	gorm.Model

	// VectorStoreID is the ID of the vector store.
	VectorStoreID string `gorm:"uniqueIndex:idx_collectionmeta_vsid_key"`

	Key   string `gorm:"uniqueIndex:idx_collectionmeta_vsid_key"`
	Value string

	Version int
}

CollectionMetadata represents the metadata of a collection.

type CollectionStatus

type CollectionStatus string

CollectionStatus represents the status of a collection.

type ExpiresAfterAnchor

type ExpiresAfterAnchor string

ExpiresAfterAnchor represents the anchor for the expiration time.

type File

type File struct {
	gorm.Model

	VectorStoreID string `gorm:"uniqueIndex:idx_file_vector_store_id_file_id"`

	// FileID is the file ID.
	FileID string `gorm:"uniqueIndex:idx_file_vector_store_id_file_id"`

	// UsageBytes is the total vector store usage in bytes. Note that this may be different from the original file size.
	UsageBytes int64

	// TODO(guangrui): handle status update.
	Status FileStatus

	LastErrorCode    LastErrorCode
	LastErrorMessage string

	ChunkingStrategyType ChunkingStrategyType
	MaxChunkSizeTokens   int64
	ChunkOverlapTokens   int64

	Version int
}

File represents a file.

type FileStatus

type FileStatus string

FileStatus represents the status of a file.

type LastErrorCode

type LastErrorCode string

LastErrorCode represents the error code of the last error.

type S

type S struct {
	// contains filtered or unexported fields
}

S represents the data store.

func New

func New(db *gorm.DB) *S

New creates a new store instance.

func NewTest

func NewTest(t *testing.T) (*S, func())

NewTest returns a new test store.

func (*S) AutoMigrate

func (s *S) AutoMigrate() error

AutoMigrate sets up the auto-migration task of the database.

func (*S) CreateCollection

func (s *S) CreateCollection(c *Collection) error

CreateCollection creates a new collection.

func (*S) CreateCollectionMetadata

func (s *S) CreateCollectionMetadata(cm *CollectionMetadata) error

CreateCollectionMetadata creates a new collection metadata.

func (*S) CreateFile

func (s *S) CreateFile(f *File) error

CreateFile creates a new file.

func (*S) DeleteAllCollectionMetadatasByVectorStoreID

func (s *S) DeleteAllCollectionMetadatasByVectorStoreID(vectorStoreID string) error

DeleteAllCollectionMetadatasByVectorStoreID deletes all metadata of the collection.

func (*S) DeleteAllFilesByVectorStoreID

func (s *S) DeleteAllFilesByVectorStoreID(vectorStoreID string) error

DeleteAllFilesByVectorStoreID deletes all files of the collection.

func (*S) DeleteCollection

func (s *S) DeleteCollection(projectID string, vectorStoreID string) error

DeleteCollection deletes the collection.

func (*S) DeleteCollectionMetadata

func (s *S) DeleteCollectionMetadata(id uint) error

DeleteCollectionMetadata deletes the metadata for the collection.

func (*S) DeleteFile

func (s *S) DeleteFile(vectorStoreID, fileID string) error

DeleteFile deletes the file.

func (*S) GetCollectionByName

func (s *S) GetCollectionByName(projectID, name string) (*Collection, error)

GetCollectionByName gets a collection.

func (*S) GetCollectionByVectorStoreID

func (s *S) GetCollectionByVectorStoreID(projectID string, vectorStoreID string) (*Collection, error)

GetCollectionByVectorStoreID gets a collection.

func (*S) GetFileByFileID

func (s *S) GetFileByFileID(vectorStoreID, fileID string) (*File, error)

GetFileByFileID gets a file.

func (*S) ListCollectionMetadataByVectorStoreID

func (s *S) ListCollectionMetadataByVectorStoreID(vectorStoreID string) ([]*CollectionMetadata, error)

ListCollectionMetadataByVectorStoreID lists metadata of a collections.

func (*S) ListCollections

func (s *S) ListCollections(projectID string) ([]*Collection, error)

ListCollections lists collections.

func (*S) ListCollectionsWithPagination

func (s *S) ListCollectionsWithPagination(
	projectID string,
	afterCreatedAt time.Time,
	afterID uint,
	order string,
	limit int,
) ([]*Collection, bool, error)

ListCollectionsWithPagination finds collections with pagination. Collections are returned in the order of VectorStoreID.

func (*S) ListFiles

func (s *S) ListFiles(vectorStoreID string) ([]*File, error)

ListFiles lists files.

func (*S) ListFilesWithPagination

func (s *S) ListFilesWithPagination(
	vectorStoreID string,
	afterCreatedAt time.Time,
	afterID uint,
	order string,
	limit int,
) ([]*File, bool, error)

ListFilesWithPagination finds files with pagination. Files are returned in the order of created_at.

func (*S) Transaction

func (s *S) Transaction(f func(*gorm.DB) error) error

Transaction runs a given function in a transaction.

func (*S) UpdateCollection

func (s *S) UpdateCollection(nc *Collection) error

UpdateCollection updates the collection.

func (*S) UpdateCollectionMetadata

func (s *S) UpdateCollectionMetadata(cm *CollectionMetadata) error

UpdateCollectionMetadata updates the metadata of a collection.

Jump to

Keyboard shortcuts

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