semantic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToFloat32

func BytesToFloat32(data []byte) []float32

func CosineSimilarity

func CosineSimilarity(a, b []float32) float32

func Float32ToBytes

func Float32ToBytes(data []float32) []byte

Types

type EmbeddingProvider

type EmbeddingProvider interface {
	Embed(ctx context.Context, text string) ([]float32, error)
}

type EmbeddingRequest

type EmbeddingRequest struct {
	Input string `json:"input"`
	Model string `json:"model"`
}

type EmbeddingResponse

type EmbeddingResponse struct {
	Data []struct {
		Embedding []float64 `json:"embedding"`
	} `json:"data"`
}

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type OpenAIProvider

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

func NewOpenAIProvider

func NewOpenAIProvider() *OpenAIProvider

func (*OpenAIProvider) CheckSimilarity

func (p *OpenAIProvider) CheckSimilarity(ctx context.Context, prompt1, prompt2 string) (bool, error)

func (*OpenAIProvider) Embed

func (p *OpenAIProvider) Embed(ctx context.Context, text string) ([]float32, error)

type SemanticEngine

type SemanticEngine struct {
	Provider      EmbeddingProvider
	Store         Storage
	Verifier      Verifier
	HighThreshold float32
	LowThreshold  float32
}

func NewSemanticEngine

func NewSemanticEngine(p EmbeddingProvider, s Storage, v Verifier, highThreshold, lowThreshold float32) *SemanticEngine

func (*SemanticEngine) FindSimilar

func (se *SemanticEngine) FindSimilar(ctx context.Context, text string) (string, float32, error)

type Storage

type Storage interface {
	GetAllEmbeddings(ctx context.Context) (map[string][]byte, error)
	GetPrompt(ctx context.Context, key string) (string, error)
}

type VerificationRequest

type VerificationRequest struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
}

type VerificationResponse

type VerificationResponse struct {
	Choices []struct {
		Message Message `json:"message"`
	} `json:"choices"`
}

type Verifier

type Verifier interface {
	CheckSimilarity(ctx context.Context, prompt1, prompt2 string) (bool, error)
}

Jump to

Keyboard shortcuts

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