embeddings

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRateLimit = errors.New("openai: rate limit exceeded (HTTP 429)")

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float32) float64

func EntityText

func EntityText(e memory.Entity) string

Types

type Config

type Config struct {
	OpenAIKey string

	OpenAIModel string

	OllamaURL string

	OllamaModel string
}

func ConfigFromEnv

func ConfigFromEnv() Config

type DocEmbedding

type DocEmbedding struct {
	DocID string

	ContentHash string

	Vector []float32
}

type DocResult

type DocResult struct {
	DocID string `json:"doc_id"`

	Repo string `json:"repo"`

	Path string `json:"path"`

	Score float64 `json:"score"`

	Snippet string `json:"snippet"`
}

type DocStore

type DocStore interface {
	ListDocs(repoName string) ([]memory.DocRecord, error)
}

type EmbeddingProvider

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

	ModelKey() string
}

func NewOllamaProvider

func NewOllamaProvider(baseURL, model string) EmbeddingProvider

func NewOpenAIProvider

func NewOpenAIProvider(apiKey, model string) EmbeddingProvider

func NewOpenAIProviderWithURL

func NewOpenAIProviderWithURL(apiKey, model, baseURL string) EmbeddingProvider

func NewProvider

func NewProvider(cfg Config) EmbeddingProvider

type EntityEmbedding

type EntityEmbedding struct {
	EntityName string

	ObsHash string

	Vector []float32
}

type EntityOpener

type EntityOpener interface {
	OpenNodes(names []string) (memory.KnowledgeGraph, error)
}

type EntityResult

type EntityResult struct {
	Name string `json:"name"`

	EntityType string `json:"entity_type"`

	Score float64 `json:"score"`

	Observations []string `json:"observations"`
}

type GraphReader

type GraphReader interface {
	ReadGraph() (memory.KnowledgeGraph, error)
}

type Indexer

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

func NewIndexer

func NewIndexer(provider EmbeddingProvider, store *VectorStore, docs DocStore, entities EntityOpener) *Indexer

func (*Indexer) IndexDocs

func (idx *Indexer) IndexDocs(ctx context.Context, repoFullName string)

func (*Indexer) IndexEntities

func (idx *Indexer) IndexEntities(ctx context.Context, names []string)

func (*Indexer) ScheduleEntities

func (idx *Indexer) ScheduleEntities(names []string)

type SemanticSearcher

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

func NewSemanticSearcher

func NewSemanticSearcher(provider EmbeddingProvider, store *VectorStore, indexer *Indexer, docs DocStore, entities GraphReader) *SemanticSearcher

func (*SemanticSearcher) Enabled

func (ss *SemanticSearcher) Enabled() bool

func (*SemanticSearcher) IndexDocs

func (ss *SemanticSearcher) IndexDocs(ctx context.Context, repo string)

func (*SemanticSearcher) ScheduleIndexEntities

func (ss *SemanticSearcher) ScheduleIndexEntities(names []string)

func (*SemanticSearcher) SearchDocs

func (ss *SemanticSearcher) SearchDocs(ctx context.Context, query, repo string, topK int) ([]DocResult, int, error)

func (*SemanticSearcher) SearchEntities

func (ss *SemanticSearcher) SearchEntities(ctx context.Context, query string, topK int) ([]EntityResult, int, error)

type VectorStore

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

func NewVectorStore

func NewVectorStore(db *gorm.DB) (*VectorStore, error)

func (*VectorStore) DeleteDocByID

func (vs *VectorStore) DeleteDocByID(docID string) error

func (*VectorStore) DeleteEntityByName

func (vs *VectorStore) DeleteEntityByName(entityName string) error

func (*VectorStore) LoadDocEmbeddings

func (vs *VectorStore) LoadDocEmbeddings(modelKey string) ([]DocEmbedding, error)

func (*VectorStore) LoadEntityEmbeddings

func (vs *VectorStore) LoadEntityEmbeddings(modelKey string) ([]EntityEmbedding, error)

func (*VectorStore) UpsertDoc

func (vs *VectorStore) UpsertDoc(docID, contentHash, modelKey string, vector []float32) error

func (*VectorStore) UpsertEntity

func (vs *VectorStore) UpsertEntity(entityName, obsHash, modelKey string, vector []float32) error

Jump to

Keyboard shortcuts

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