document

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: 4 Imported by: 0

Documentation

Overview

Package document defines the Document entity and its lifecycle states.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CountFilter

type CountFilter struct {
	// CollectionID filters by collection. Empty means all collections.
	CollectionID id.CollectionID
	// State filters by document state. Empty means all states.
	State State
	// Search filters by title, matched exactly as ListFilter.Search.
	Search string
	// 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
	// UpdatedBefore counts only documents last updated before this instant.
	// Zero means no filter.
	UpdatedBefore time.Time
}

CountFilter controls filtering for document count queries.

type Document

type Document struct {
	weave.Entity

	ID            id.DocumentID     `json:"id" bun:"id,pk"`
	CollectionID  id.CollectionID   `json:"collection_id" bun:"collection_id,notnull"`
	TenantID      string            `json:"tenant_id" bun:"tenant_id,notnull"`
	Title         string            `json:"title,omitempty" bun:"title"`
	Source        string            `json:"source,omitempty" bun:"source"`
	SourceType    string            `json:"source_type,omitempty" bun:"source_type"`
	ContentHash   string            `json:"content_hash" bun:"content_hash,notnull"`
	ContentLength int               `json:"content_length" bun:"content_length,notnull,default:0"`
	ChunkCount    int               `json:"chunk_count" bun:"chunk_count,notnull,default:0"`
	Metadata      map[string]string `json:"metadata" bun:"metadata,notnull,default:'{}'"`
	State         State             `json:"state" bun:"state,notnull,default:'pending'"`
	Error         string            `json:"error,omitempty" bun:"error"`
	// SourceKey identifies the source this document is the current version
	// of within its collection. Empty means the document is not source-managed.
	SourceKey string `json:"source_key,omitempty" bun:"source_key,notnull,default:''"`
}

Document represents an ingested document within a collection.

type ListFilter

type ListFilter struct {
	// CollectionID filters by collection. Empty means all collections.
	CollectionID id.CollectionID
	// State filters by document state. Empty means all states.
	State State
	// Search filters documents by title (case-insensitive substring match).
	Search string
	// SourceKey filters by exact source key. Empty means any.
	SourceKey string
	// ContentHash filters by exact content hash. Empty means any.
	ContentHash string
	// Limit is the maximum number of documents to return. Zero means no limit.
	Limit int
	// Offset is the number of documents to skip.
	Offset int
	// SortDesc lists newest first. The default is oldest first, which API
	// clients paging by offset already depend on.
	SortDesc bool
	// 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
}

ListFilter controls pagination and filtering for document list queries.

type State

type State string

State represents the lifecycle state of a document.

const (
	// StatePending means the document has been created but not yet processed.
	StatePending State = "pending"
	// StateProcessing means the document is currently being chunked/embedded.
	StateProcessing State = "processing"
	// StateReady means the document has been fully processed and is searchable.
	StateReady State = "ready"
	// StateFailed means the document processing failed.
	StateFailed State = "failed"
	// StateSuperseded means a newer version of the document's source
	// replaced it. The engine purges it right after the swap.
	StateSuperseded State = "superseded"
)

type Store

type Store interface {
	// CreateDocument persists a new document. Its TenantID must be the
	// context tenant, and its collection must belong to that tenant, else
	// weave.ErrCollectionNotFound.
	CreateDocument(ctx context.Context, doc *Document) error

	// GetDocument retrieves a document by ID.
	GetDocument(ctx context.Context, docID id.DocumentID) (*Document, error)

	// UpdateDocument persists changes to an existing document. A document
	// never changes collection: a different CollectionID is not-found.
	UpdateDocument(ctx context.Context, doc *Document) error

	// DeleteDocument removes a document by ID.
	DeleteDocument(ctx context.Context, docID id.DocumentID) error

	// ListDocuments returns documents matching the given filter.
	ListDocuments(ctx context.Context, filter *ListFilter) ([]*Document, error)

	// CountDocuments returns the number of documents matching the given filter.
	CountDocuments(ctx context.Context, filter *CountFilter) (int64, error)

	// DeleteDocumentsByCollection removes all documents belonging to a collection.
	DeleteDocumentsByCollection(ctx context.Context, colID id.CollectionID) error
}

Store defines the persistence contract for documents. 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