index

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package index builds an on-disk, searchable map of expertise from connector records and ranks people and channels for a query without an LLM.

Index

Constants

View Source
const DefaultHalfLife = 180 * 24 * time.Hour

DefaultHalfLife is the age at which a dated record's weight halves.

Variables

This section is empty.

Functions

This section is empty.

Types

type Changes

type Changes struct {
	// PeopleJoined are people present now but not before.
	PeopleJoined []string `json:"people_joined,omitempty"`
	// PeopleLeft are people present before but not now.
	PeopleLeft []string `json:"people_left,omitempty"`
	// TeamsAdded are teams present now but not before.
	TeamsAdded []string `json:"teams_added,omitempty"`
	// TeamsRemoved are teams present before but not now.
	TeamsRemoved []string `json:"teams_removed,omitempty"`
	// ChannelsAdded are channels present now but not before.
	ChannelsAdded []string `json:"channels_added,omitempty"`
	// ChannelsRemoved are channels present before but not now.
	ChannelsRemoved []string `json:"channels_removed,omitempty"`
}

Changes describes which people, teams, and channels entered or left the graph between a previous index and a new one.

func Diff

func Diff(prev, cur *model.Graph) Changes

Diff reports what changed from the prev graph to the cur graph.

func (Changes) Empty

func (c Changes) Empty() bool

Empty reports whether nothing changed.

func (Changes) Summary

func (c Changes) Summary() string

Summary is a one-line count of the changes.

type Embedder

type Embedder interface {
	// Embed returns the embedding vector for text.
	Embed(ctx context.Context, text string) ([]float32, error)
}

Embedder turns text into a vector. The llm package's Ollama client satisfies it.

type Index

type Index struct {
	// Graph is the entity graph this index was built from.
	Graph *model.Graph
	// contains filtered or unexported fields
}

Index is a searchable expertise index over people and channels.

func Load

func Load(path string) (*Index, error)

Load reads an index previously written by Save.

func New

func New() *Index

New returns an empty index with initialized maps.

func (*Index) Add added in v0.1.3

func (ix *Index) Add(records []connector.Record)

Add merges records into the current index, accumulating onto whatever is already present. Person records merge by email or id, channel records by name. It leaves embeddings unchanged; call Embed to refresh vectors after adding.

func (*Index) Alias added in v0.1.6

func (ix *Index) Alias(a, b model.ID)

Alias records that two identifiers belong to the same person. Records indexed afterward key by the canonical identifier; call Canonicalize to also join people already in the graph.

func (*Index) Build

func (ix *Index) Build(records []connector.Record)

Build replaces the index contents with data derived from records.

func (*Index) Canonicalize added in v0.1.6

func (ix *Index) Canonicalize()

Canonicalize rewrites the graph so every person appears once under their canonical identifier, merging people the identity resolver maps together and re-pointing channel members and manager links. Run it after loading aliases over an existing index; records added after aliases load already key canonically. A merged person keeps at most one embedding vector, so re-embed afterward when vectors matter.

func (*Index) Embed

func (ix *Index) Embed(ctx context.Context, e Embedder) error

Embed fills per-person and per-channel vectors by embedding a text representation of each entity. An error from e aborts and is returned.

func (*Index) HasEmbeddings

func (ix *Index) HasEmbeddings() bool

HasEmbeddings reports whether the index holds vectors to search semantically.

func (*Index) LoadAliases added in v0.1.6

func (ix *Index) LoadAliases(path string) error

LoadAliases merges a JSON alias file into the index's identity resolver so records indexed afterward key by their canonical identifier. Call Canonicalize to also join people already in the graph.

func (*Index) Profile added in v0.1.15

func (ix *Index) Profile(id model.ID) (Profile, bool)

Profile returns the full profile for id, resolving identity aliases, or false when the person is not in the graph.

func (*Index) Save

func (ix *Index) Save(path string) (err error)

Save writes the index to path as JSON, creating parent directories as needed.

func (*Index) Search

func (ix *Index) Search(query string, limit int) []model.Match

Search ranks people for query and returns up to limit matches. A non-positive limit returns all matches.

func (*Index) SearchChannels

func (ix *Index) SearchChannels(query string, limit int) []model.ChannelMatch

SearchChannels ranks channels for query and returns up to limit matches, each carrying the most relevant active members. A non-positive limit returns all.

func (*Index) SemanticChannels

func (ix *Index) SemanticChannels(query []float32, limit int) []model.ChannelMatch

SemanticChannels ranks channels by cosine similarity to the query vector and attaches the members most similar to the query.

func (*Index) SemanticPeople

func (ix *Index) SemanticPeople(query []float32, limit int) []model.Match

SemanticPeople ranks people by cosine similarity to the query vector.

func (*Index) SetFeedback added in v0.1.10

func (ix *Index) SetFeedback(entries []feedback.Entry)

SetFeedback gives the index user votes to apply during ranking. Later calls replace earlier ones. Person votes resolve through identity aliases, so a vote on any of a person's identifiers lands on the canonical entry.

func (*Index) SetFeedbackStrength added in v0.1.18

func (ix *Index) SetFeedbackStrength(step float64, maxNet int)

SetFeedbackStrength tunes how hard votes move ranking: step is the per-vote score multiplier and maxNet clamps the net votes applied to one result. A step at or below one, or a maxNet at or below zero, turns feedback off.

func (*Index) SetHalfLife added in v0.1.7

func (ix *Index) SetHalfLife(d time.Duration)

SetHalfLife sets the age at which a dated record's weight halves. Zero or negative disables recency decay.

type Profile added in v0.1.15

type Profile struct {
	// Person is the profiled individual.
	Person *model.Person
	// Team is the person's team, if known.
	Team *model.Team
	// Org is the person's organization, if known.
	Org *model.Org
	// Manager is the person's manager, if known and indexed.
	Manager *model.Person
	// Channels lists the channels naming the person as an active member.
	Channels []*model.Channel
}

Profile is everything the index knows about one person: the person, their org placement, their manager, and the channels they are active in.

Jump to

Keyboard shortcuts

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