chunk

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package chunk defines the Chunk entity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	ID           id.ChunkID        `json:"id" bun:"id,pk"`
	DocumentID   id.DocumentID     `json:"document_id" bun:"document_id,notnull"`
	CollectionID id.CollectionID   `json:"collection_id" bun:"collection_id,notnull"`
	TenantID     string            `json:"tenant_id" bun:"tenant_id,notnull"`
	Content      string            `json:"content" bun:"content,notnull"`
	Index        int               `json:"index" bun:"index,notnull"`
	StartOffset  int               `json:"start_offset" bun:"start_offset,notnull,default:0"`
	EndOffset    int               `json:"end_offset" bun:"end_offset,notnull,default:0"`
	TokenCount   int               `json:"token_count" bun:"token_count,notnull,default:0"`
	Metadata     map[string]string `json:"metadata" bun:"metadata,notnull,default:'{}'"`
	ParentID     string            `json:"parent_id,omitempty" bun:"parent_id"`
	CreatedAt    time.Time         `json:"created_at" bun:"created_at,notnull,default:current_timestamp"`
}

Chunk represents a portion of a document that has been split for embedding and retrieval.

type CountFilter

type CountFilter struct {
	// CollectionID filters by collection. Empty means all collections.
	CollectionID id.CollectionID
	// DocumentID filters by document. Empty means all documents.
	DocumentID id.DocumentID
	// Tenant is the old explicit tenant filter.
	//
	// Deprecated: the tenant comes from the context (weave.WithTenant). A non-nil value must equal it.
	Tenant *string
}

CountFilter controls filtering for chunk count queries.

type ListFilter

type ListFilter struct {
	// DocumentID filters by document. Empty means all documents.
	DocumentID id.DocumentID
	// CollectionID filters by collection. Empty means all collections.
	CollectionID id.CollectionID
	// Tenant is the old explicit tenant filter.
	//
	// Deprecated: the tenant comes from the context (weave.WithTenant). A non-nil value must equal it.
	Tenant *string
	// Limit is the maximum number of chunks to return. Zero means no limit.
	Limit int
	// Offset is the number of chunks to skip.
	Offset int
}

ListFilter controls paging and filtering for chunk listings. Results are ordered by document ID, then by index within each document.

type Store

type Store interface {
	// CreateChunkBatch persists a batch of chunks. Every chunk's TenantID
	// must be the context tenant, its document must belong to that tenant
	// (else weave.ErrDocumentNotFound) and sit in the chunk's collection, and
	// its ID must be new. One chunk that fails refuses the whole batch.
	CreateChunkBatch(ctx context.Context, chunks []*Chunk) error

	// GetChunk retrieves a chunk by ID.
	GetChunk(ctx context.Context, chunkID id.ChunkID) (*Chunk, error)

	// ListChunksByDocument returns all chunks belonging to a document, ordered by index.
	ListChunksByDocument(ctx context.Context, docID id.DocumentID) ([]*Chunk, error)

	// ListChunks returns chunks matching the filter, ordered by document
	// then index.
	ListChunks(ctx context.Context, filter *ListFilter) ([]*Chunk, error)

	// DeleteChunksByDocument removes all chunks belonging to a document.
	DeleteChunksByDocument(ctx context.Context, docID id.DocumentID) error

	// DeleteChunksByCollection removes all chunks belonging to a collection.
	DeleteChunksByCollection(ctx context.Context, colID id.CollectionID) error

	// CountChunks returns the number of chunks matching the given filter.
	CountChunks(ctx context.Context, filter *CountFilter) (int64, error)
}

Store defines the persistence contract for chunks. Every method is scoped to the context tenant; see store.Store for the rules.

Jump to

Keyboard shortcuts

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