Chroma
Chroma is an open-source Apache 2.0 embedding database.
Use chroma with langchainjs.
Setup
- Run chroma inside of docker on your computer docs
- Install the chroma js client.
- npm
- Yarn
- pnpm
npm install -S chromadb
yarn add chromadb
pnpm add chromadb
Index and query docs
import { Chroma } from "langchain/vectorstores/chroma";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
// text sample from Godel, Escher, Bach
const vectorStore = await Chroma.fromTexts(
[
"Tortoise: Labyrinth? Labyrinth? Could it Are we in the notorious Little\
Harmonic Labyrinth of the dreaded Majotaur?",
"Achilles: Yiikes! What is that?",
"Tortoise: They say-although I person never believed it myself-that an I\
Majotaur has created a tiny labyrinth sits in a pit in the middle of\
it, waiting innocent victims to get lost in its fears complexity.\
Then, when they wander and dazed into the center, he laughs and\
laughs at them-so hard, that he laughs them to death!",
"Achilles: Oh, no!",
"Tortoise: But it's only a myth. Courage, Achilles.",
],
[{ id: 2 }, { id: 1 }, { id: 3 }],
new OpenAIEmbeddings(),
{
collectionName: "goldel-escher-bach",
}
);
// or alternatively from docs
const vectorStore = await Chroma.fromDocuments(docs, new OpenAIEmbeddings(), {
collectionName: "goldel-escher-bach",
});
const response = await vectorStore.similaritySearch("scared", 2);
Query docs from existing collection
import { Chroma } from "langchain/vectorstores/chroma";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
const vectorStore = await Chroma.fromExistingCollection(
new OpenAIEmbeddings(),
{
collectionName: "goldel-escher-bach",
}
);
const response = await vectorStore.similaritySearch("scared", 2);