Documentation
¶
Index ¶
- Variables
- func LoadAndPreprocess(ctx context.Context, r io.Reader, width, height int, opts ...Option) ([]float32, error)
- func LoadAndPreprocessFile(ctx context.Context, path string, width, height int, opts ...Option) ([]float32, error)
- func SplitIntoSentences(context string) []string
- type DataType
- type Embedder
- type EmbedderConfig
- type EmbedderOption
- type Encoding
- type Model
- func (m *Model) Close(ctx context.Context) error
- func (m *Model) GetInputCount(ctx context.Context) (uint32, error)
- func (m *Model) GetInputDims(ctx context.Context, inputIndex uint32) ([]int32, error)
- func (m *Model) GetOutputCount(ctx context.Context) (uint32, error)
- func (m *Model) Run(ctx context.Context, inputs ...*Tensor) ([]*Tensor, error)
- type Option
- type PoolingType
- type PruneResult
- type Pruner
- type PrunerConfig
- type RerankResult
- type Reranker
- type Runtime
- type RuntimeConfig
- type RuntimeOption
- type SentencePieceTokenizer
- type Tensor
- type Tokenizer
Constants ¶
This section is empty.
Variables ¶
var ( ImageNetMean = [3]float32{0.485, 0.456, 0.406} ImageNetStd = [3]float32{0.229, 0.224, 0.225} )
ImageNet normalization constants.
Functions ¶
func LoadAndPreprocess ¶
func LoadAndPreprocess(ctx context.Context, r io.Reader, width, height int, opts ...Option) ([]float32, error)
LoadAndPreprocess loads an image from a reader, resizes it, and converts to NCHW tensor format.
func LoadAndPreprocessFile ¶
func LoadAndPreprocessFile(ctx context.Context, path string, width, height int, opts ...Option) ([]float32, error)
LoadAndPreprocessFile loads an image from a file path and preprocesses it.
func SplitIntoSentences ¶
SplitIntoSentences splits context into sentences for reranking.
Types ¶
type Embedder ¶
type Embedder struct {
// contains filtered or unexported fields
}
Embedder produces embeddings from text.
func NewEmbedder ¶
func NewEmbedder(ctx context.Context, rt *Runtime, model *Model, tk Tokenizer, opts ...EmbedderOption) (*Embedder, error)
NewEmbedder creates a new Embedder.
type EmbedderConfig ¶
type EmbedderConfig struct {
Normalize bool
Pooling PoolingType
}
EmbedderConfig configures embedding behavior.
type EmbedderOption ¶
type EmbedderOption func(*EmbedderConfig)
EmbedderOption configures an Embedder.
func WithEmbeddingNormalize ¶
func WithEmbeddingNormalize(normalize bool) EmbedderOption
WithEmbeddingNormalize enables or disables L2 normalization.
func WithEmbeddingPooling ¶
func WithEmbeddingPooling(pooling PoolingType) EmbedderOption
WithEmbeddingPooling sets the pooling strategy.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model represents a loaded machine learning model.
func (*Model) GetInputCount ¶
GetInputCount returns the number of model inputs.
func (*Model) GetInputDims ¶
GetInputDims returns the dimensions of the specified input.
func (*Model) GetOutputCount ¶
GetOutputCount returns the number of model outputs.
type Option ¶
type Option func(*imageConfig)
Option configures image preprocessing.
func WithNormalization ¶
WithNormalization overrides the mean and std used for normalization.
type PoolingType ¶
type PoolingType int
PoolingType defines how to pool token embeddings.
const (
PoolingMean PoolingType = iota + 1
)
type PruneResult ¶
type PruneResult struct {
PrunedDocument string
KeptRatio float32
KeptTokens int
TotalTokens int
RankingScore float32
Probability float32
}
PruneResult represents the result of document pruning.
type Pruner ¶
type Pruner struct {
// contains filtered or unexported fields
}
Pruner prunes documents based on a query.
func NewPruner ¶
func NewPruner(ctx context.Context, rt *Runtime, model *Model, tk Tokenizer, cfg PrunerConfig) (*Pruner, error)
NewPruner creates a new Pruner.
func (*Pruner) Prune ¶
Prune processes a query and document through OpenProvence model for pruning and ranking.
func (*Pruner) PruneBatch ¶
func (p *Pruner) PruneBatch(ctx context.Context, query string, documents []string) ([]*PruneResult, error)
PruneBatch processes multiple documents with the same query.
type PrunerConfig ¶
type PrunerConfig struct {
Threshold float32
}
PrunerConfig configures pruning behavior.
type RerankResult ¶
RerankResult represents a single rerank result with score and passage.
type Reranker ¶
type Reranker struct {
// contains filtered or unexported fields
}
Reranker reranks passages by relevance.
func NewReranker ¶
NewReranker creates a new Reranker.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime holds the WebAssembly runtime and module.
func NewRuntime ¶
func NewRuntime(ctx context.Context, opts ...RuntimeOption) (*Runtime, error)
NewRuntime creates a new RTen runtime from a WASM module.
func (*Runtime) NewTensorFloat32 ¶
NewTensorFloat32 creates a float32 tensor.
type RuntimeConfig ¶
RuntimeConfig holds options for runtime creation.
type RuntimeOption ¶
type RuntimeOption func(*RuntimeConfig)
RuntimeOption configures runtime creation.
type SentencePieceTokenizer ¶
type SentencePieceTokenizer struct {
// contains filtered or unexported fields
}
SentencePieceTokenizer implements Tokenizer using sentencepiece.
func NewSentencePiece ¶
func NewSentencePiece(modelPath string) (*SentencePieceTokenizer, error)
NewSentencePiece creates a new SentencePiece tokenizer from a model file.
func (*SentencePieceTokenizer) Decode ¶
func (t *SentencePieceTokenizer) Decode(ids []int) string
Decode converts token IDs back to text.
type Tensor ¶
type Tensor struct {
// contains filtered or unexported fields
}
Tensor represents a tensor in the WASM memory.
func (*Tensor) Float32Data ¶
Float32Data returns the float32 data of the tensor.