kjarni

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float32) float32

compute cosine similarity between two vectors

Types

type Classifier

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

func NewClassifier

func NewClassifier(model string, opts ...Option) (*Classifier, error)

func (*Classifier) Classify

func (c *Classifier) Classify(text string) (*ClassifyResult, error)

run classifier

func (*Classifier) Close

func (c *Classifier) Close() error

Close resources

func (*Classifier) NumLabels

func (c *Classifier) NumLabels() int

return the number of labels the model supports

type ClassifyResult

type ClassifyResult struct {
	Label     string
	Score     float32
	AllScores []LabelScore
}

output of a classification

func (*ClassifyResult) String

func (r *ClassifyResult) String() string

func (*ClassifyResult) ToJSON

func (r *ClassifyResult) ToJSON() string

type Embedder

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

encode text into vector embeddings

func NewEmbedder

func NewEmbedder(model string, opts ...Option) (*Embedder, error)

func (*Embedder) Close

func (e *Embedder) Close() error

release the embedder resources

func (*Embedder) Dim

func (e *Embedder) Dim() int

return the dimensionality of the embedding model

func (*Embedder) Encode

func (e *Embedder) Encode(text string) ([]float32, error)

return the embedding vector for the given text

func (*Embedder) EncodeBatch

func (e *Embedder) EncodeBatch(texts []string) ([][]float32, error)

encodes multiple texts

func (*Embedder) Similarity

func (e *Embedder) Similarity(a, b string) (float32, error)

returns the cosine similarity between two texts

type ErrorCode

type ErrorCode int32
const (
	ErrOk              ErrorCode = 0
	ErrNullPointer     ErrorCode = 1
	ErrInvalidUtf8     ErrorCode = 2
	ErrModelNotFound   ErrorCode = 3
	ErrLoadFailed      ErrorCode = 4
	ErrInferenceFailed ErrorCode = 5
	ErrGpuUnavailable  ErrorCode = 6
	ErrInvalidConfig   ErrorCode = 7
	ErrCancelled       ErrorCode = 8
	ErrTimeout         ErrorCode = 9
	ErrStreamEnded     ErrorCode = 10
	ErrUnknown         ErrorCode = 255
)

type IndexStats

type IndexStats struct {
	DocumentsIndexed int
	ChunksCreated    int
	Dimension        int
	SizeBytes        uint64
	FilesProcessed   int
	FilesSkipped     int
	ElapsedMs        uint64
}

statistics from an indexing operation.

type Indexer

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

create search indexes from files

func NewIndexer

func NewIndexer(model string, opts ...Option) (*Indexer, error)

new indexer

func (*Indexer) Close

func (idx *Indexer) Close() error

releases resources

func (*Indexer) Create

func (idx *Indexer) Create(indexPath string, inputs []string) (*IndexStats, error)

build a new index from the given dirs

type KjarniError

type KjarniError struct {
	Code    ErrorCode
	Message string
}

func (*KjarniError) Error

func (e *KjarniError) Error() string

type LabelScore

type LabelScore struct {
	Label string
	Score float32
}

single label with score

type Option

type Option func(*options)

func WithDevice

func WithDevice(device string) Option

func WithQuiet

func WithQuiet(quiet bool) Option

type RerankResult

type RerankResult struct {
	Index    int
	Score    float32
	Document string
}

single reranked document

type Reranker

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

score query-document relevance using a cross-encoder

func NewReranker

func NewReranker(opts ...Option) (*Reranker, error)

new reranker

func (*Reranker) Close

func (r *Reranker) Close() error

release resources

func (*Reranker) Rerank

func (r *Reranker) Rerank(query string, documents []string) ([]RerankResult, error)

rerank scores and sort documents by relevance to the query

func (*Reranker) RerankTopK

func (r *Reranker) RerankTopK(query string, documents []string, k int) ([]RerankResult, error)

scores documents and returns the top k

func (*Reranker) Score

func (r *Reranker) Score(query, document string) (float32, error)

return relevance score for a query-document pair

type SearchMode

type SearchMode int

search strategy hybrid, semantic, keyword(bm25)

const (
	Keyword  SearchMode = 0
	Semantic SearchMode = 1
	Hybrid   SearchMode = 2
)

type SearchResult

type SearchResult struct {
	Score float32
	Text  string
}

single search result

type Searcher

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

Searcher queries indexes created by Indexer

func NewSearcher

func NewSearcher(model string, rerankerModel string, opts ...Option) (*Searcher, error)

new searcher

func (*Searcher) Close

func (s *Searcher) Close() error

releases resources

func (*Searcher) Search

func (s *Searcher) Search(indexPath string, query string, mode SearchMode) ([]SearchResult, error)

queries the index with the given mode

Directories

Path Synopsis
examples
classify command
embed command
rerank command

Jump to

Keyboard shortcuts

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