embeddings

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineDistance

func CosineDistance(v1, v2 []float64) float64

func CreateEmbedding

func CreateEmbedding(ollamaUrl string, query llm.Query4Embedding, id string) (llm.VectorRecord, error)

func GenerateContextFromSimilarities added in v0.0.4

func GenerateContextFromSimilarities(similarities []llm.VectorRecord) string

GenerateContextFromSimilarities generates the context content from a slice of vector records.

Parameters: - similarities: a slice of llm.VectorRecord representing the similarities.

Returns: - string: the generated context content in XML format.

Types

type BboltVectorStore added in v0.0.2

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

func (*BboltVectorStore) Get added in v0.0.2

func (bvs *BboltVectorStore) Get(id string) (llm.VectorRecord, error)

func (*BboltVectorStore) GetAll added in v0.0.2

func (bvs *BboltVectorStore) GetAll() ([]llm.VectorRecord, error)

func (*BboltVectorStore) Initialize added in v0.0.2

func (bvs *BboltVectorStore) Initialize(dbPath string) error

func (*BboltVectorStore) Save added in v0.0.2

func (bvs *BboltVectorStore) Save(vectorRecord llm.VectorRecord) (llm.VectorRecord, error)

TODO: if vectorRecord.Id == "" create a uuid

func (*BboltVectorStore) SearchMaxSimilarity added in v0.0.2

func (bvs *BboltVectorStore) SearchMaxSimilarity(embeddingFromQuestion llm.VectorRecord) (llm.VectorRecord, error)

SearchMaxSimilarity searches for the vector record in the BboltVectorStore that has the maximum cosine distance similarity to the given embeddingFromQuestion.

Parameters: - embeddingFromQuestion: the vector record to compare similarities with.

Returns: - llm.VectorRecord: the vector record with the maximum cosine distance similarity. - error: an error if any occurred during the search.

func (*BboltVectorStore) SearchSimilarities added in v0.0.2

func (bvs *BboltVectorStore) SearchSimilarities(embeddingFromQuestion llm.VectorRecord, limit float64) ([]llm.VectorRecord, error)

SearchSimilarities searches for vector records in the BboltVectorStore that have a cosine distance similarity greater than or equal to the given limit.

Parameters:

  • embeddingFromQuestion: the vector record to compare similarities with.
  • limit: the minimum cosine distance similarity threshold.

Returns:

  • []llm.VectorRecord: a slice of vector records that have a cosine distance similarity greater than or equal to the limit.
  • error: an error if any occurred during the search.

type EmbeddingResponse

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

type MemoryVectorStore

type MemoryVectorStore struct {
	Records map[string]llm.VectorRecord
}

func (*MemoryVectorStore) Get

func (mvs *MemoryVectorStore) Get(id string) (llm.VectorRecord, error)

func (*MemoryVectorStore) GetAll

func (mvs *MemoryVectorStore) GetAll() ([]llm.VectorRecord, error)

func (*MemoryVectorStore) Save

func (mvs *MemoryVectorStore) Save(vectorRecord llm.VectorRecord) (llm.VectorRecord, error)

func (*MemoryVectorStore) SearchMaxSimilarity

func (mvs *MemoryVectorStore) SearchMaxSimilarity(embeddingFromQuestion llm.VectorRecord) (llm.VectorRecord, error)

SearchMaxSimilarity finds the vector record in MemoryVectorStore with the maximum cosine distance similarity to the provided vector record.

Parameters:

  • embeddingFromQuestion: llm.VectorRecord - the vector record to compare similarities with.

Returns:

  • llm.VectorRecord: The vector record with the maximum similarity.
  • error: Error if any.

func (*MemoryVectorStore) SearchSimilarities

func (mvs *MemoryVectorStore) SearchSimilarities(embeddingFromQuestion llm.VectorRecord, limit float64) ([]llm.VectorRecord, error)

SearchSimilarities searches for vector records in the MemoryVectorStore that have a cosine distance similarity greater than or equal to the given limit.

Parameters:

  • embeddingFromQuestion: the vector record to compare similarities with.
  • limit: the minimum cosine distance similarity threshold.

Returns:

  • []llm.VectorRecord: a slice of vector records that have a cosine distance similarity greater than or equal to the limit.
  • error: an error if any occurred during the search.

type VectorStore

type VectorStore interface {
	Get(id string) (llm.VectorRecord, error)
	GetAll() ([]llm.VectorRecord, error)
	Save(vectorRecord llm.VectorRecord) (llm.VectorRecord, error)
	SearchMaxSimilarity(embeddingFromQuestion llm.VectorRecord) (llm.VectorRecord, error)
	SearchSimilarities(embeddingFromQuestion llm.VectorRecord, limit float64) ([]llm.VectorRecord, error)
}

Jump to

Keyboard shortcuts

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