vectorgo

package module
v0.0.0-...-7cd10a6 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 8 Imported by: 0

README

VectorGo

VectorGo is a powerful and flexible SQLite powered Vector Database in pure Go with optional embeddings generation via the OpenAI API. It allows users to store, search, and manage vector embeddings easily.

Features

  • SQLite powered vector database
  • Pure Go implementation
  • Option to generate embeddings using OpenAI API
  • Support for various vector operations
  • Easy to integrate into your projects

Installation

To get started with VectorGo, simply add the package to your Go project:

go get -u github.com/chand1012/vectorgo

Usage

First, create a new VectorDB instance by providing a path to the SQLite database file and an OpenAI API key:

import (
        "github.com/chand1012/vectorgo"
)

config := &vectorgo.VectorDBConfig{
        Path:      "path/to/your/db/file",
        OpenAIKey: "your_openai_api_key",
}

vdb, err := vectorgo.NewVectorDB(config)

Now, you can start adding embeddings by providing identifiers and content:

err := vdb.Add("identifier", "content")

To search for an embedding in plain text, use the Search method:

results, err := vdb.Search("query text", 10)

Additionally, you can check if an embedding exists or matches content, delete embeddings, and perform other operations. For more information, check out the documentation.

Contributing

Feel free to contribute to VectorGo by submitting issues, pull requests, or feature requests.

License

VectorGo is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilarity

func CosineSimilarity(a []float64, b []float64) (float64, error)

Types

type EmbeddingSearchResult

type EmbeddingSearchResult struct {
	Embedding        db.Embedding
	CosineSimilarity float64
}

type VectorDB

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

VectorDB is a wrapper around a gorm.DB instance for supporting vector operations

func NewVectorDB

func NewVectorDB(config *VectorDBConfig) (*VectorDB, error)

NewVectorDB creates a new VectorDB instance

func (*VectorDB) Add

func (v *VectorDB) Add(identifier, content string) error

Adds an embedding to the database

func (*VectorDB) AddEmbedding

func (v *VectorDB) AddEmbedding(identifier, content string, embedding []float64) error

func (*VectorDB) CheckEmbeddingExists

func (v *VectorDB) CheckEmbeddingExists(identifier string) (bool, error)

func (*VectorDB) CheckEmbeddingMatches

func (v *VectorDB) CheckEmbeddingMatches(identifier, content string) (bool, error)

Given an identifier and content, check if the embedding's content matches

func (*VectorDB) DeleteEmbeddingByID

func (v *VectorDB) DeleteEmbeddingByID(id uint) error

Deletes the embedding. Also clears the embedding values

func (*VectorDB) DeleteEmbeddingByIdentifier

func (v *VectorDB) DeleteEmbeddingByIdentifier(identifier string) error

func (*VectorDB) GetEmbeddingByID

func (v *VectorDB) GetEmbeddingByID(id uint) (db.Embedding, error)

func (*VectorDB) GetEmbeddingByIdentifier

func (v *VectorDB) GetEmbeddingByIdentifier(identifier string) (db.Embedding, error)

func (*VectorDB) Search

func (v *VectorDB) Search(query string, limit uint) ([]EmbeddingSearchResult, error)

Searches for an embedding in plain text

func (*VectorDB) SearchByEmbedding

func (v *VectorDB) SearchByEmbedding(query []float64, limit uint) ([]EmbeddingSearchResult, error)

type VectorDBConfig

type VectorDBConfig struct {
	Path      string
	OpenAIKey string
}

Config for VectorDB

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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