rag

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListAllCollections

func ListAllCollections(dbPath string) []string

ListAllCollections lists all collections in the database

Types

type CollectionState

type CollectionState struct {
	ExternalSources []*ExternalSource `json:"external_sources"`
}

CollectionState represents the persistent state of a collection

type Engine

type Engine interface {
	Store(s string, metadata map[string]string) (engine.Result, error)
	StoreDocuments(s []string, metadata map[string]string) ([]engine.Result, error)
	GetEmbeddingDimensions() (int, error)
	Reset() error
	Search(s string, similarEntries int) ([]types.Result, error)
	Count() int
	Delete(where map[string]string, whereDocuments map[string]string, ids ...string) error
	GetByID(id string) (types.Result, error)
	GetBySource(source string) ([]types.Result, error)
}

type ExternalSource

type ExternalSource struct {
	URL            string
	UpdateInterval time.Duration
	LastUpdate     time.Time
}

ExternalSource represents a source that needs to be periodically updated

type PersistentKB

type PersistentKB struct {
	Engine
	sync.Mutex
	// contains filtered or unexported fields
}

func NewPersistentChromeCollection

func NewPersistentChromeCollection(llmClient *openai.Client, collectionName, dbPath, filePath, embeddingModel string, maxChunkSize, chunkOverlap int) (*PersistentKB, error)

NewPersistentChromeCollection creates a new persistent knowledge base collection using the ChromemDB engine. Returns an error instead of exiting so embedded callers (long-running servers) can degrade gracefully when the engine or embedding service is transiently unavailable.

func NewPersistentCollectionKB

func NewPersistentCollectionKB(stateFile, assetDir string, store Engine, maxChunkSize, chunkOverlap int, llmClient *openai.Client, embeddingModel string) (*PersistentKB, error)

func NewPersistentLocalAICollection

func NewPersistentLocalAICollection(llmClient *openai.Client, apiURL, apiKey, collectionName, dbPath, filePath, embeddingModel string, maxChunkSize, chunkOverlap int) (*PersistentKB, error)

NewPersistentLocalAICollection creates a new persistent knowledge base collection using the LocalAI stores engine. Returns an error instead of exiting so embedded callers can degrade gracefully on transient failures.

func NewPersistentPostgresCollection

func NewPersistentPostgresCollection(llmClient *openai.Client, collectionName, dbPath, filePath, embeddingModel string, maxChunkSize, chunkOverlap int, databaseURL string) (*PersistentKB, error)

NewPersistentPostgresCollection creates a new persistent knowledge base collection using the PostgreSQL engine. Returns an error instead of exiting so embedded callers can degrade gracefully when the embedding service or PostgreSQL is transiently unavailable.

func (*PersistentKB) AddExternalSource

func (db *PersistentKB) AddExternalSource(source *ExternalSource) error

AddExternalSource adds an external source to the collection

func (*PersistentKB) Count

func (db *PersistentKB) Count() int

func (*PersistentKB) EntryExists

func (db *PersistentKB) EntryExists(entry string) bool

EntryExists checks if an entry with the given name exists. It searches by the full key first, then falls back to matching by base filename.

func (*PersistentKB) GetEntryContent

func (db *PersistentKB) GetEntryContent(entry string) ([]types.Result, error)

GetEntryContent returns all chunks (content, id, metadata) for the given entry. It uses Engine.GetBySource to find chunks by source metadata.

func (*PersistentKB) GetEntryFileContent

func (db *PersistentKB) GetEntryFileContent(entry string) (content string, chunkCount int, err error)

GetEntryFileContent returns the full content of the stored file (same text that was chunked, without overlap) and the number of chunks it occupies. This avoids returning overlapping chunk content.

func (*PersistentKB) GetEntryFilePath

func (db *PersistentKB) GetEntryFilePath(entry string) (string, error)

GetEntryFilePath returns the filesystem path of the stored file for the given entry.

func (*PersistentKB) GetExternalSources

func (db *PersistentKB) GetExternalSources() []*ExternalSource

GetExternalSources returns the list of external sources for this collection

func (*PersistentKB) ListDocuments

func (db *PersistentKB) ListDocuments() []string

ListDocuments returns the list of documents in the knowledge base. Each entry includes the key (uuid/filename).

func (*PersistentKB) RemoveEntry

func (db *PersistentKB) RemoveEntry(entry string) error

func (*PersistentKB) RemoveExternalSource

func (db *PersistentKB) RemoveExternalSource(url string) error

RemoveExternalSource removes an external source from the collection

func (*PersistentKB) Repopulate

func (db *PersistentKB) Repopulate() error

func (*PersistentKB) Reset

func (db *PersistentKB) Reset() error

func (*PersistentKB) Search

func (db *PersistentKB) Search(s string, similarEntries int) ([]types.Result, error)

func (*PersistentKB) Store

func (db *PersistentKB) Store(entry string, metadata map[string]string) (string, error)

Store stores an entry in the persistent knowledge base.

func (*PersistentKB) StoreOrReplace

func (db *PersistentKB) StoreOrReplace(entry string, metadata map[string]string) (string, error)

type SourceManager

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

SourceManager manages external sources for collections

func NewSourceManager

func NewSourceManager(config *sources.Config) *SourceManager

NewSourceManager creates a new source manager

func (*SourceManager) AddSource

func (sm *SourceManager) AddSource(collectionName, url string, updateInterval time.Duration) error

AddSource adds a new external source to a collection

func (*SourceManager) RegisterCollection

func (sm *SourceManager) RegisterCollection(name string, collection *PersistentKB)

RegisterCollection registers a collection with the source manager

func (*SourceManager) RemoveSource

func (sm *SourceManager) RemoveSource(collectionName, url string) error

RemoveSource removes an external source from a collection

func (*SourceManager) Start

func (sm *SourceManager) Start()

Start starts the background service

func (*SourceManager) Stop

func (sm *SourceManager) Stop()

Stop stops the background service

Directories

Path Synopsis
localai
TODO: this is a duplicate of LocalAI/core/store/client.go
TODO: this is a duplicate of LocalAI/core/store/client.go

Jump to

Keyboard shortcuts

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