collections

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInProcessBackend

func NewInProcessBackend(cfg *Config) (Backend, *State)

NewInProcessBackend creates in-process state (load from disk, start sourceManager) and returns a Backend and the State. The caller can use RAGProviderFromState to create a RAG provider.

func RAGProviderFromState

func RAGProviderFromState(cs *State) func(collectionName string) (agent.RAGDB, state.KBCompactionClient, bool)

RAGProviderFromState returns a RAG provider function from a State. External consumers (e.g. LocalAI) can call NewInProcessBackend to get the state, then pass it here to create a RAG provider for the agent pool.

Types

type Backend

type Backend interface {
	ListCollections() ([]string, error)
	CreateCollection(name string) error
	Upload(collection, filename string, fileBody io.Reader) (string, error)
	ListEntries(collection string) ([]string, error)
	GetEntryContent(collection, entry string) (content string, chunkCount int, err error)
	Search(collection, query string, maxResults int) ([]SearchResult, error)
	Reset(collection string) error
	DeleteEntry(collection, entry string) (remainingEntries []string, err error)
	AddSource(collection, url string, intervalMin int) error
	RemoveSource(collection, url string) error
	ListSources(collection string) ([]SourceInfo, error)
	EntryExists(collection, entry string) bool
	// GetEntryFilePath returns the filesystem path of the stored file for the
	// given entry. This is used to serve the original uploaded binary file.
	GetEntryFilePath(collection, entry string) (string, error)
}

Backend is the interface used by REST handlers for collection operations. It is implemented by in-process state (embedded) or by an HTTP client.

type CollectionList

type CollectionList map[string]*rag.PersistentKB

CollectionList maps collection names to their persistent knowledge bases.

type Config

type Config struct {
	LLMAPIURL        string
	LLMAPIKey        string
	LLMModel         string
	CollectionDBPath string
	FileAssets       string
	VectorEngine     string
	EmbeddingModel   string
	MaxChunkingSize  int
	ChunkOverlap     int
	DatabaseURL      string
}

Config holds the configuration for the in-process collections backend.

type SearchResult

type SearchResult struct {
	Content    string            `json:"content"`
	Metadata   map[string]string `json:"metadata,omitempty"`
	ID         string            `json:"id,omitempty"`
	Similarity float32           `json:"similarity,omitempty"`
}

SearchResult is a single search result (content + metadata) for API responses.

type SourceInfo

type SourceInfo struct {
	URL            string    `json:"url"`
	UpdateInterval int       `json:"update_interval"` // minutes
	LastUpdate     time.Time `json:"last_update"`
}

SourceInfo is a single external source for a collection.

type State

type State struct {
	Mu               sync.RWMutex
	Collections      CollectionList
	SourceManager    *rag.SourceManager
	EnsureCollection func(name string) (*rag.PersistentKB, bool) // get-or-create for internal RAG
}

State holds in-memory state for the collections API.

Jump to

Keyboard shortcuts

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