forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update chromasdk peer dep, fix issues with using existing collections…
…, update docs
- Loading branch information
Showing
10 changed files
with
163 additions
and
120 deletions.
There are no files selected for viewing
65 changes: 0 additions & 65 deletions
65
docs/docs/modules/indexes/vector_stores/integrations/chroma.md
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
docs/docs/modules/indexes/vector_stores/integrations/chroma.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# Chroma | ||
|
||
Chroma is an open-source Apache 2.0 embedding database. | ||
|
||
## Setup | ||
|
||
1. Run chroma with Docker on your computer [docs](https://docs.trychroma.com/api-reference) | ||
2. Install the Chroma JS SDK. | ||
|
||
```bash npm2yarn | ||
npm install -S chromadb | ||
``` | ||
|
||
## Usage, Index and query Documents | ||
|
||
import FromDocs from "@examples/indexes/vector_stores/chroma/fromDocs.ts"; | ||
|
||
<CodeBlock language="typescript">{FromDocs}</CodeBlock> | ||
|
||
## Usage, Index and query texts | ||
|
||
import FromTexts from "@examples/indexes/vector_stores/chroma/fromTexts.ts"; | ||
|
||
<CodeBlock language="typescript">{FromTexts}</CodeBlock> | ||
|
||
## Usage, Query docs from existing collection | ||
|
||
import Search from "@examples/indexes/vector_stores/chroma/search.ts"; | ||
|
||
<CodeBlock language="typescript">{Search}</CodeBlock> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Chroma } from "langchain/vectorstores/chroma"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
import { TextLoader } from "langchain/document_loaders/fs/text"; | ||
|
||
// Create docs with a loader | ||
const loader = new TextLoader("src/document_loaders/example_data/example.txt"); | ||
const docs = await loader.load(); | ||
|
||
// Create vector store and index the docs | ||
const vectorStore = await Chroma.fromDocuments(docs, new OpenAIEmbeddings(), { | ||
collectionName: "a-test-collection", | ||
}); | ||
|
||
// Search for the most similar document | ||
const response = await vectorStore.similaritySearch("hello", 1); | ||
|
||
console.log(response); | ||
/* | ||
[ | ||
Document { | ||
pageContent: 'Foo\nBar\nBaz\n\n', | ||
metadata: { source: 'src/document_loaders/example_data/example.txt' } | ||
} | ||
] | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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: "godel-escher-bach", | ||
} | ||
); | ||
|
||
const response = await vectorStore.similaritySearch("scared", 2); | ||
|
||
console.log(response); | ||
/* | ||
[ | ||
Document { pageContent: 'Achilles: Oh, no!', metadata: {} }, | ||
Document { | ||
pageContent: 'Achilles: Yiikes! What is that?', | ||
metadata: { id: 1 } | ||
} | ||
] | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Chroma } from "langchain/vectorstores/chroma"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
const vectorStore = await Chroma.fromExistingCollection( | ||
new OpenAIEmbeddings(), | ||
{ collectionName: "godel-escher-bach" } | ||
); | ||
|
||
const response = await vectorStore.similaritySearch("scared", 2); | ||
console.log(response); | ||
/* | ||
[ | ||
Document { pageContent: 'Achilles: Oh, no!', metadata: {} }, | ||
Document { | ||
pageContent: 'Achilles: Yiikes! What is that?', | ||
metadata: { id: 1 } | ||
} | ||
] | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters