chroma

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: MIT Imports: 12 Imported by: 2

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.

Note: Additional ways to run Chroma locally can be found in Chroma Cookbook

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.5.0. 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.5.0
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=http://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
	OpenAIOrgIDEnvVarName  = "OPENAI_ORGANIZATION"
	ChromaURLKeyEnvVarName = "CHROMA_URL"
	DefaultNameSpace       = "langchain"
	DefaultNameSpaceKey    = "nameSpace"
	DefaultDistanceFunc    = chromatypes.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 chromatypes.DistanceFunction) Option

WithDistanceFunction specifies the distance function which will be used (default is L2) see: https://github.com/amikos-tech/chroma-go/blob/ab1339d0ee1a863be7d6773bcdedc1cfd08e3d77/types/types.go#L22

func WithEmbedder

func WithEmbedder(e embeddings.Embedder) Option

WithEmbedder is an option for setting the embedder to use.

func WithIncludes

func WithIncludes(includes []chromatypes.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.

func WithOpenAIOrganization

func WithOpenAIOrganization(openAiOrganization string) Option

WithOpenAIOrganization is an option for setting the OpenAI organization id.

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(ctx context.Context,
	docs []schema.Document,
	options ...vectorstores.Option,
) ([]string, error)

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

func (Store) RemoveCollection

func (s Store) RemoveCollection() error

func (Store) SimilaritySearch

func (s Store) SimilaritySearch(ctx 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