Skip to content

Commit

Permalink
community[patch]: Update JSDoc on Chroma vectorstore (langchain-ai#6509)
Browse files Browse the repository at this point in the history
* partners[minor]: Update JSDocs on vectorstores

* update examples
  • Loading branch information
bracesproul authored Aug 13, 2024
1 parent bfebaee commit 642db08
Showing 1 changed file with 131 additions and 3 deletions.
134 changes: 131 additions & 3 deletions libs/langchain-community/src/vectorstores/chroma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,137 @@ export interface ChromaDeleteParams<T> {
}

/**
* The main class that extends the `VectorStore` class. It provides
* methods for interacting with the Chroma database, such as adding
* documents, deleting documents, and searching for similar vectors.
* Chroma vector store integration.
*
* Setup:
* Install `@langchain/community` and `chromadb`, then clone the official `ChromaDB` repository.
*
* ```bash
* npm install @langchain/community chromadb
* ```
*
* ```bash
* git clone https://github.com/chroma-core/chroma.git
* ```
*
* Next, navigate into the `chroma` directory and start the docker container:
*
* ```bash
* cd ./chroma
*
* docker compose up
* ```
*
* ## [Constructor args](https://api.js.langchain.com/classes/langchain_community_vectorstores_chroma.Chroma.html#constructor)
*
* <details open>
* <summary><strong>Instantiate</strong></summary>
*
* ```typescript
* import { Chroma } from '@langchain/community/vectorstores/chroma';
* import { OpenAIEmbeddings } from '@langchain/openai';
*
* const vectorStore = new Chroma(
* new OpenAIEmbeddings(),
* {
* collectionName: "foo",
* url: "http://localhost:8000", // URL of the Chroma server
* }
* );
* ```
* </details>
*
* <br />
*
* <details>
* <summary><strong>Add documents</strong></summary>
*
* ```typescript
* import { Document } from '@langchain/core/documents';
*
* const document1 = new Document({ pageContent: "foo", metadata: { baz: "bar" } });
* const document2 = new Document({ pageContent: "thud", metadata: { bar: "baz" } });
* const document3 = new Document({ pageContent: "i will be deleted :(" });
*
* const documents = [document1, document2, document3];
* const ids = ["1", "2", "3"];
* await vectorStore.addDocuments(documents, { ids });
* ```
* </details>
*
* <br />
*
* <details>
* <summary><strong>Delete documents</strong></summary>
*
* ```typescript
* await vectorStore.delete({ ids: ["3"] });
* ```
* </details>
*
* <br />
*
* <details>
* <summary><strong>Similarity search</strong></summary>
*
* ```typescript
* const results = await vectorStore.similaritySearch("thud", 1);
* for (const doc of results) {
* console.log(`* ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
* }
* // Output: * thud [{"baz":"bar"}]
* ```
* </details>
*
* <br />
*
*
* <details>
* <summary><strong>Similarity search with filter</strong></summary>
*
* ```typescript
* const resultsWithFilter = await vectorStore.similaritySearch("thud", 1, { baz: "bar" });
*
* for (const doc of resultsWithFilter) {
* console.log(`* ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
* }
* // Output: * foo [{"baz":"bar"}]
* ```
* </details>
*
* <br />
*
*
* <details>
* <summary><strong>Similarity search with score</strong></summary>
*
* ```typescript
* const resultsWithScore = await vectorStore.similaritySearchWithScore("qux", 1);
* for (const [doc, score] of resultsWithScore) {
* console.log(`* [SIM=${score.toFixed(6)}] ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
* }
* // Output: * [SIM=0.000000] qux [{"bar":"baz","baz":"bar"}]
* ```
* </details>
*
* <br />
*
* <details>
* <summary><strong>As a retriever</strong></summary>
*
* ```typescript
* const retriever = vectorStore.asRetriever({
* searchType: "mmr",
* k: 1,
* });
* const resultAsRetriever = await retriever.invoke("thud");
* console.log(resultAsRetriever);
*
* // Output: [Document({ metadata: { "baz":"bar" }, pageContent: "thud" })]
* ```
* </details>
*
* <br />
*/
export class Chroma extends VectorStore {
declare FilterType: Where;
Expand Down

0 comments on commit 642db08

Please sign in to comment.