msgindex

package
v0.16.154 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	RoleUser  = "user"
	RoleAgent = "agent"
)

Roles of a message.

View Source
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

func Snippet

func Snippet(text string, words []string) string

Snippet is the words of text around the first word that one of the query words begins; whitespace is one space.

func Tokens

func Tokens(text string) []string

Tokens are the distinct words of a text, folded.

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 Hit

type Hit struct {
	Conv    string
	Entry   string
	At      int64
	Role    string
	Turn    string
	Snippet string
}

Hit is a message found, with the words around the match.

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

func Open(dir string) (*Index, error)

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) Close

func (ix *Index) Close() error

Close releases the log.

func (*Index) Compact

func (ix *Index) Compact() error

Compact writes the log again with the live messages only.

func (*Index) Count

func (ix *Index) Count() int

Count is how many messages the index holds.

func (*Index) Mark

func (ix *Index) Mark(conv string, size int64)

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

func (ix *Index) Messages(conv string) []Doc

Messages are the messages of a conversation in the order they were written.

func (*Index) Put

func (ix *Index) Put(docs ...Doc)

Put keeps messages of one conversation, replacing those it has under the same entry; one that did not change is skipped.

func (*Index) Read

func (ix *Index) Read(conv string) bool

Read says whether the conversation was read whole at least once.

func (*Index) Remove

func (ix *Index) Remove(conv string)

Remove forgets a conversation.

func (*Index) Replace

func (ix *Index) Replace(conv string, size int64, docs []Doc)

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.

func (*Index) Search

func (ix *Index) Search(q string, o Options) []Hit

Search finds the messages that hold every word of q (each a prefix of a word of the message), the newest first.

func (*Index) Size

func (ix *Index) Size(conv string) (int64, bool)

Size is the transcript size the conversation was read at; false when it never was read whole.

type Options

type Options struct {
	// Limit is how many hits at most (default 40).
	Limit int
	// PerConv is how many hits a conversation gives at most (default 3).
	PerConv int
}

Options of a search.

Jump to

Keyboard shortcuts

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