Documentation
¶
Index ¶
- Constants
- Variables
- func CallRAGQuery(inst *instance.Instance, method string, payload []byte, path string, ...) (*http.Response, error)
- func CleanInstance(inst *instance.Instance) error
- func DeleteIndexStatus(inst *instance.Instance, docID string) error
- func Index(inst *instance.Instance, logger logger.Logger, msg IndexMessage) error
- func Purge(inst *instance.Instance) error
- func Query(inst *instance.Instance, logger logger.Logger, query QueryMessage) error
- func Reconcile(inst *instance.Instance, dirID string) (int, error)
- func Reset(inst *instance.Instance) error
- func SetIndexStatus(inst *instance.Instance, docID, newStatus, rev string) error
- type ChatConversation
- func (c *ChatConversation) Clone() couchdb.Doc
- func (c *ChatConversation) DocType() string
- func (c *ChatConversation) ID() string
- func (c *ChatConversation) Included() []jsonapi.Object
- func (c *ChatConversation) Links() *jsonapi.LinksList
- func (c *ChatConversation) Relationships() jsonapi.RelationshipMap
- func (c *ChatConversation) Rev() string
- func (c *ChatConversation) SetID(id string)
- func (c *ChatConversation) SetRev(rev string)
- type ChatMessage
- type ChatPayload
- type IndexMessage
- type IndexStatus
- type PruneResult
- type QueryMessage
- type Source
Constants ¶
const ( UserRole = "user" AssistantRole = "assistant" SystemRole = "system" Temperature = 0.3 // LLM parameter - Sampling temperature, lower is more deterministic, higher is more creative. TopP = 1 // LLM parameter - Alternative to temperature, take the tokens with the top p probability. LogProbs = false // LLM parameter - Whether to return log probabilities of the output tokens. )
const ( // BatchSize is the maximal number of documents manipulated at once by the // worker. BatchSize = 100 // MaxBatchRetries caps the attempts at a batch that keeps failing on // retryable errors, so one poisoned file cannot stall a trigger. The // worker retries a failed job MaxExecCount times (3, see worker/rag), and // every execution consumes one attempt: 15 is about five trigger firings. MaxBatchRetries = 15 )
const ( StatusSuccess = "success" StatusError = "error" StatusNotSupported = "notsupported" )
const DocTypeVersion = "1"
DocTypeVersion represents the doctype version. Each time this document structure is modified, update this value
const IndexStatusPath = "/ai/index/status"
IndexStatusPath is the path of the route on which the RAG indexer posts the indexation status of a file. It is what inst.PageURL takes to build the callback_url given to the indexer.
Variables ¶
var ErrAssistantNotFound = errors.New("assistant not found")
ErrAssistantNotFound is returned when a conversation references an assistant that is gone (deleted, or never created). The query must fail: answering anyway would silently widen a possibly folder-scoped conversation to whole-instance retrieval.
var ErrUnknownFolder = errors.New("the folder is in no assistant's knowledge base")
ErrUnknownFolder is returned by Reconcile when the given folder is in no assistant's knowledge base: there is nothing to index in it.
var ErrWorkspaceMissing = errors.New("the knowledge base folder is not indexed yet")
ErrWorkspaceMissing is returned by checkWorkspace when the knowledge base folder has no workspace on openRAG: no rag-index job has reconciled it yet.
Functions ¶
func CallRAGQuery ¶
func CleanInstance ¶
func DeleteIndexStatus ¶
DeleteIndexStatus removes the indexation status of a document. One that never had a status is not an error.
func Purge ¶
Purge deletes everything openRAG holds for the instance: its workspaces, its files and the partition itself. The index statuses are dropped, and so is the rag-index checkpoint, so that the next run indexes the whole instance again from the beginning of the changes feed.
func Reconcile ¶
Reconcile pushes a reconcile job for the knowledge base folder, or one per knowledge base folder when dirID is empty. It returns the number of jobs pushed.
Types ¶
type ChatConversation ¶
type ChatConversation struct {
DocID string `json:"_id"`
DocRev string `json:"_rev,omitempty"`
Messages []ChatMessage `json:"messages"`
CozyMetadata *metadata.CozyMetadata `json:"cozyMetadata"`
Rels jsonapi.RelationshipMap `json:"relationships,omitempty"`
}
func Chat ¶
func Chat(inst *instance.Instance, payload ChatPayload) (*ChatConversation, error)
func (*ChatConversation) Clone ¶
func (c *ChatConversation) Clone() couchdb.Doc
func (*ChatConversation) DocType ¶
func (c *ChatConversation) DocType() string
func (*ChatConversation) ID ¶
func (c *ChatConversation) ID() string
func (*ChatConversation) Included ¶
func (c *ChatConversation) Included() []jsonapi.Object
func (*ChatConversation) Links ¶
func (c *ChatConversation) Links() *jsonapi.LinksList
func (*ChatConversation) Relationships ¶
func (c *ChatConversation) Relationships() jsonapi.RelationshipMap
func (*ChatConversation) Rev ¶
func (c *ChatConversation) Rev() string
func (*ChatConversation) SetID ¶
func (c *ChatConversation) SetID(id string)
func (*ChatConversation) SetRev ¶
func (c *ChatConversation) SetRev(rev string)
type ChatMessage ¶
type ChatPayload ¶
type IndexMessage ¶
type IndexMessage struct {
Doctype string `json:"doctype"`
ReconcileDirID string `json:"reconcile_dir_id,omitempty"`
}
IndexMessage is the message of rag-index triggers and jobs. Without ReconcileDirID the job processes the changes feed; with it, the job walks the folder's subtree (initial indexing of a new knowledge base folder).
type IndexStatus ¶
type IndexStatus struct {
CouchID string `json:"_id,omitempty"`
CouchRev string `json:"_rev,omitempty"`
Indexed bool `json:"indexed"`
Status string `json:"status,omitempty"`
// Revision of the io.cozy.files document this status describes. Callbacks
// are ordered on it.
DocRev string `json:"docRev,omitempty"`
LastSuccessDate *time.Time `json:"lastSuccessDate,omitempty"`
LastErrorDate *time.Time `json:"lastErrorDate,omitempty"`
// Read it with relData["_id"], not with Relationship.ResourceIdentifier():
// the latter looks for "id"/"type" and would silently return an empty
// reference.
Rels jsonapi.RelationshipMap `json:"relationships,omitempty"`
}
IndexStatus is the RAG indexation status of a document. Its identifier is the identifier of the document it describes.
func NewIndexStatus ¶
func NewIndexStatus(docID string) *IndexStatus
func (*IndexStatus) Clone ¶
func (s *IndexStatus) Clone() couchdb.Doc
func (*IndexStatus) DocType ¶
func (s *IndexStatus) DocType() string
func (*IndexStatus) ID ¶
func (s *IndexStatus) ID() string
func (*IndexStatus) Rev ¶
func (s *IndexStatus) Rev() string
func (*IndexStatus) SetID ¶
func (s *IndexStatus) SetID(id string)
func (*IndexStatus) SetRev ¶
func (s *IndexStatus) SetRev(rev string)
type PruneResult ¶
type PruneResult struct {
FilesScanned int `json:"files_scanned"`
FilesDeleted int `json:"files_deleted"`
WorkspacesDeleted int `json:"workspaces_deleted"`
}
PruneResult summarizes a Prune run.
func Prune ¶
func Prune(inst *instance.Instance) (PruneResult, error)
Prune deletes from openRAG what no knowledge base folder claims any more: the files gone or trashed in the VFS, the files outside every knowledge base folder, and the workspaces of the folders that are in no knowledge base. The index status of a deleted file is dropped too.
type QueryMessage ¶
type Source ¶
type Source struct {
SourceType string `json:"sourceType"`
// Document source fields
ID string `json:"id,omitempty"`
DocType string `json:"doctype,omitempty"`
Filename string `json:"filename,omitempty"`
FileURL string `json:"fileUrl,omitempty"`
ChunkURL string `json:"chunkUrl,omitempty"`
Page int `json:"page,omitempty"`
EmailPreview string `json:"email.preview,omitempty"`
RelationshipID string `json:"relationship_id,omitempty"`
ParentID string `json:"parent_id,omitempty"`
Subject string `json:"email.subject,omitempty"`
Datetime string `json:"datetime,omitempty"`
// Web source fields
URL string `json:"url,omitempty"`
Title string `json:"title,omitempty"`
Snippet string `json:"snippet,omitempty"`
}