Documentation
¶
Overview ¶
Package msgindex is the full-text index over the messages of conversations: what the person wrote and what the agent answered, not the tool noise. It is an inverted index in memory over an append-only log in the runtime's data dir; the log is a cache of the transcripts, which stay the truth, so a log that is lost or damaged is built again.
Words are lowercased with ё folded into е, a query word matches the words it is a prefix of, and a message must hold every word of the query. The text of a message stays in the log and is read for the few hits shown.
Index ¶
- Constants
- func Snippet(text string, words []string) string
- func Tokens(text string) []string
- type Doc
- type Hit
- type Index
- func (ix *Index) Close() error
- func (ix *Index) Compact() error
- func (ix *Index) Count() int
- func (ix *Index) Mark(conv string, size int64)
- func (ix *Index) Messages(conv string) []Doc
- func (ix *Index) Put(docs ...Doc)
- func (ix *Index) Read(conv string) bool
- func (ix *Index) Remove(conv string)
- func (ix *Index) Replace(conv string, size int64, docs []Doc)
- func (ix *Index) Search(q string, o Options) []Hit
- func (ix *Index) Size(conv string) (int64, bool)
- type Options
Constants ¶
const ( RoleUser = "user" RoleAgent = "agent" )
Roles of a message.
const (
TextMax = 16000
)
Words longer than this (hashes, encoded blobs) are not indexed; a text is indexed up to TextMax runes.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Doc ¶
type Doc struct {
Conv string `json:"c"`
Entry string `json:"e"`
At int64 `json:"t"`
Role string `json:"r"`
// Turn is the turn the message belongs to, "" for one outside any.
Turn string `json:"u,omitempty"`
Text string `json:"x"`
}
Doc is one message.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is safe for concurrent use. A nil *Index finds nothing and keeps nothing.
func Open ¶
Open reads the log in dir and goes on appending to it. A log that cannot be read whole is built again from what is readable; an error means the index cannot be kept at all, and the caller goes without.
func (*Index) Mark ¶
Mark says that the messages of the conversation were taken up to size bytes of its transcript, without a message changing (live entries keep it current).
func (*Index) Messages ¶
Messages are the messages of a conversation in the order they were written.
func (*Index) Put ¶
Put keeps messages of one conversation, replacing those it has under the same entry; one that did not change is skipped.
func (*Index) Replace ¶
Replace is what a reading of a whole conversation gives: its messages, and the size of the transcript they were read at. Messages the index holds that the reading no longer has are forgotten.