chroma

package
v0.0.0-...-7b6d569 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 12 Imported by: 0

README

Chroma Support

You can access Chroma via the included implementation of the vectorstores.VectorStore interface by creating and using a Chroma client Store instance with the New function API.

Client/Server

Until an "in-memory" version is released, only client/server mode is available.

Use the WithChromaURL API or the CHROMA_URL environment variable to specify the URL of the Chroma server when creating the client instance.

Using OpenAI LLM

To use the OpenAI LLM with Chroma, use either the WithOpenAiAPIKey API or the OPENAI_API_KEY environment variable when creating the client.

Running With Docker

Running a Chroma server in a local docker instance can be especially useful for testing and development workflows. An example invocation scenario is presented below:

Starting the Chroma Server

As of this writing, the newest release of the Chroma docker image is chroma:0.4.9. Running it directly while exposing its port to your local machine can be accomplished with:

$ docker run -p 8000:8000 ghcr.io/chroma-core/chroma:0.4.9
Running an Example langchaingo Application

With the "Simple Docker Server" running (see above), running the included example langchaingo app should produce the following result:

$ export CHROMA_URL=localhost:8000
$ export OPENAI_API_KEY=YourOpenApiKeyGoesHere
$ go run ./examples/chroma-vectorstore-example/chroma_vectorstore_example.go
Results:
1. case: Up to 5 Cities in Japan
    result: Tokyo, Nagoya, Kyoto, Fukuoka, Hiroshima
2. case: A City in South America
    result: Buenos Aires
3. case: Large Cities in South America
    result: Sao Paulo, Rio de Janeiro

Tests

The test suite chroma_test.go started as a clone of the adjacent pinecone_test.go, and is initially quite sparse. Consider contributing new test cases, or adding coverage to accompany any changes made to the code.

Documentation

Overview

Package chroma contains an implementation of the vectorStore interface that connects to an external Chroma database.

Index

Constants

View Source
const (
	OpenAiAPIKeyEnvVarName = "OPENAI_API_KEY" // #nosec G101
	ChromaURLKeyEnvVarName = "CHROMA_URL"
	DefaultNameSpace       = "langchain"
	DefaultNameSpaceKey    = "nameSpace"
	DefaultDistanceFunc    = chromago.L2
)

Variables

View Source
var (
	ErrInvalidScoreThreshold    = errors.New("score threshold must be between 0 and 1")
	ErrUnexpectedResponseLength = errors.New("unexpected length of response")
	ErrNewClient                = errors.New("error creating collection")
	ErrAddDocument              = errors.New("error adding document")
	ErrRemoveCollection         = errors.New("error resetting collection")
	ErrUnsupportedOptions       = errors.New("unsupported options")
)
View Source
var ErrInvalidOptions = errors.New("invalid options")

ErrInvalidOptions is returned when the options given are invalid.

Functions

This section is empty.

Types

type Option

type Option func(p *Store)

Option is a function type that can be used to modify the client.

func WithChromaURL

func WithChromaURL(chromaURL string) Option

WithChromaURL is an option for specifying the Chroma URL. Must be set.

func WithDistanceFunction

func WithDistanceFunction(distanceFunction chromago.DistanceFunction) Option

WithDistanceFunction specifies the distance function which will be used see: https://github.com/amikos-tech/chroma-go/blob/d0087270239eccdb2f4f03d84b18d875c601ad6b/main.go#L96

func WithEmbedder

func WithEmbedder(e embeddings.Embedder) Option

WithEmbedder is an option for setting the embedder to use.

func WithIncludes

func WithIncludes(includes []chromago.QueryEnum) Option

WithIncludes is an option for setting the includes to query the vectors.

func WithNameSpace

func WithNameSpace(nameSpace string) Option

WithNameSpace sets the nameSpace used to upsert and query the vectors from.

func WithOpenAiAPIKey

func WithOpenAiAPIKey(openAiAPIKey string) Option

WithOpenAiAPIKey is an option for setting the OpenAI api key. If the option is not set the api key is read from the OPENAI_API_KEY environment variable. If the variable is not present, an error will be returned.

type Store

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

Store is a wrapper around the chromaGo API and client.

func New

func New(opts ...Option) (Store, error)

New creates an active client connection to the (specified, or default) collection in the Chroma server and returns the `Store` object needed by the other accessors.

func (Store) AddDocuments

func (s Store) AddDocuments(_ context.Context, docs []schema.Document, options ...vectorstores.Option) error

AddDocuments adds the text and metadata from the documents to the Chroma collection associated with 'Store'.

func (Store) RemoveCollection

func (s Store) RemoveCollection() error

func (Store) RemoveNamespace

func (s Store) RemoveNamespace(namespace string) error

func (Store) SimilaritySearch

func (s Store) SimilaritySearch(_ context.Context, query string, numDocuments int,
	options ...vectorstores.Option,
) ([]schema.Document, error)

Jump to

Keyboard shortcuts

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