llama_embedder

package module
v0.0.0-...-efec76b Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 13 Imported by: 0

README

Llama Embedder - Go Binding

Installation

go get github.com/amikos-tech/llamacpp-embedder/bindings/go

Usage

The following example shows how to use the go binding to load snowflake-arctic-embed-s model from HuggingFace.

Note: As part of the initialization of the binding the model

package main

import (
	"fmt"
	llama "github.com/amikos-tech/llamacpp-embedder/bindings/go"
)

func main() {
	hfRepo := "ChristianAzinn/snowflake-arctic-embed-s-gguf"
	hfFile := "snowflake-arctic-embed-s-f16.GGUF"
	e, closeFunc, err := llama.NewLlamaEmbedder(hfFile, llama.WithHFRepo(hfRepo))
	if err != nil {
        panic(err)
    }
	defer closeFunc()
	res, err := e.EmbedTexts([]string{"Hello world", "My name is Ishmael"})
    if err != nil {
        panic(err)
    }
	
    for _, r := range res {
        fmt.Println(r)
    }
}

Documentation

Index

Constants

View Source
const (
	NormalizationNone        NormalizationType = -1
	NormalizationMaxAbsInt16 NormalizationType = 0
	NormalizationTaxicab     NormalizationType = 1
	NormalizationL2          NormalizationType = 2
	PoolingNone              PoolingType       = 0
	PoolingMean              PoolingType       = 1
	PoolingCls               PoolingType       = 2
	PoolingLast              PoolingType       = 3
	LatestSharedLibVersion                     = "v0.0.8"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LlamaEmbedder

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

func NewLlamaEmbedder

func NewLlamaEmbedder(modelPath string, opts ...Option) (*LlamaEmbedder, func(), error)

func (*LlamaEmbedder) Close

func (e *LlamaEmbedder) Close()

Close closes the embedder and frees any resources

func (*LlamaEmbedder) EmbedTexts

func (e *LlamaEmbedder) EmbedTexts(texts []string) ([][]float32, error)

EmbedTexts embeds the given texts using the model

func (*LlamaEmbedder) GetMetadata

func (e *LlamaEmbedder) GetMetadata() map[string]string

GetMetadata returns the metadata associated with the model

type NormalizationType

type NormalizationType int32

type Option

type Option func(*LlamaEmbedder) error

func WithHFRepo

func WithHFRepo(repo string) Option

WithHFRepo sets the Hugging Face repo to download the model from

func WithModelCacheDir

func WithModelCacheDir(modelCacheDir string) Option

WithModelCacheDir sets the directory to cache the model. If the directory does not exist, it will be created.

func WithNormalization

func WithNormalization(norm NormalizationType) Option

WithNormalization sets the normalization type to use Possible values are NormalizationNone, NormalizationMaxAbsInt16, NormalizationTaxicab, NormalizationL2 (default)

func WithPooling

func WithPooling(pool PoolingType) Option

WithPooling sets the pooling type to use Possible values are PoolingNone, PoolingMean (default), PoolingCls, PoolingLast

func WithSharedLibraryPath

func WithSharedLibraryPath(libPath string) Option

WithSharedLibraryPath sets the shared library path to use. LlamaEmbedder will look for shared library under this path. This overrides WithSharedLibraryVersion.

func WithSharedLibraryVersion

func WithSharedLibraryVersion(version string) Option

WithSharedLibraryVersion sets the shared library version to use. This is overridden by WithSharedLibraryPath

type PoolingType

type PoolingType int32

Jump to

Keyboard shortcuts

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