embeddings

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 16 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 GenerateContentFromSimilarities added in v0.0.8

func GenerateContentFromSimilarities(similarities []llm.VectorRecord) string

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)

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.

func (*BboltVectorStore) SearchTopNSimilarities added in v0.0.8

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

SearchTopNSimilarities searches for the top N similar vector records based on the given embedding from a question. It returns a slice of vector records and an error if any. The limit parameter specifies the minimum similarity score for a record to be considered similar. The max parameter specifies the maximum number of vector records to return.

type ElasticSearchStore added in v0.1.2

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

func (*ElasticSearchStore) Initialize added in v0.1.2

func (ess *ElasticSearchStore) Initialize(addresses []string, user, pwd string, cert []byte, indexName string) error

func (*ElasticSearchStore) Save added in v0.1.2

func (ess *ElasticSearchStore) Save(vectorRecord llm.VectorRecord) (llm.VectorRecord, error)

func (*ElasticSearchStore) SearchTopNSimilarities added in v0.1.2

func (ess *ElasticSearchStore) SearchTopNSimilarities(embeddingFromQuestion llm.VectorRecord, size int) ([]llm.VectorRecord, error)

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.

func (*MemoryVectorStore) SearchTopNSimilarities added in v0.0.9

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

SearchTopNSimilarities searches for the top N similar vector records based on the given embedding from a question. It returns a slice of vector records and an error if any. The limit parameter specifies the minimum similarity score for a record to be considered similar. The max parameter specifies the maximum number of vector records to return.

type RedisVectorStore added in v0.1.1

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

func (*RedisVectorStore) Get added in v0.1.1

func (rvs *RedisVectorStore) Get(id string) (llm.VectorRecord, error)

func (*RedisVectorStore) GetAll added in v0.1.1

func (rvs *RedisVectorStore) GetAll() ([]llm.VectorRecord, error)

func (*RedisVectorStore) Initialize added in v0.1.1

func (rvs *RedisVectorStore) Initialize(redisAddr string, redisPwd string, storeName string) error

func (*RedisVectorStore) Save added in v0.1.1

func (rvs *RedisVectorStore) Save(vectorRecord llm.VectorRecord) (llm.VectorRecord, error)

func (*RedisVectorStore) SearchMaxSimilarity added in v0.1.1

func (rvs *RedisVectorStore) SearchMaxSimilarity(embeddingFromQuestion llm.VectorRecord) (llm.VectorRecord, error)

SearchMaxSimilarity searches for the vector record in the RedisVectorStore 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 (*RedisVectorStore) SearchSimilarities added in v0.1.1

func (rvs *RedisVectorStore) SearchSimilarities(embeddingFromQuestion llm.VectorRecord, limit float64) ([]llm.VectorRecord, error)

SearchSimilarities searches for vector records in the RedisVectorStore 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.

func (*RedisVectorStore) SearchTopNSimilarities added in v0.1.1

func (rvs *RedisVectorStore) SearchTopNSimilarities(embeddingFromQuestion llm.VectorRecord, limit float64, max int) ([]llm.VectorRecord, error)

SearchTopNSimilarities searches for the top N similar vector records based on the given embedding from a question. It returns a slice of vector records and an error if any. The limit parameter specifies the minimum similarity score for a record to be considered similar. The max parameter specifies the maximum number of vector records to return.

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)
	SearchTopNSimilarities(embeddingFromQuestion llm.VectorRecord, limit float64, max int) ([]llm.VectorRecord, error)
}

Jump to

Keyboard shortcuts

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