@@ -46,9 +46,137 @@ export interface ChromaDeleteParams<T> {
46
46
}
47
47
48
48
/**
49
- * The main class that extends the `VectorStore` class. It provides
50
- * methods for interacting with the Chroma database, such as adding
51
- * documents, deleting documents, and searching for similar vectors.
49
+ * Chroma vector store integration.
50
+ *
51
+ * Setup:
52
+ * Install `@langchain/community` and `chromadb`, then clone the official `ChromaDB` repository.
53
+ *
54
+ * ```bash
55
+ * npm install @langchain/community chromadb
56
+ * ```
57
+ *
58
+ * ```bash
59
+ * git clone https://github.com/chroma-core/chroma.git
60
+ * ```
61
+ *
62
+ * Next, navigate into the `chroma` directory and start the docker container:
63
+ *
64
+ * ```bash
65
+ * cd ./chroma
66
+ *
67
+ * docker compose up
68
+ * ```
69
+ *
70
+ * ## [Constructor args](https://api.js.langchain.com/classes/langchain_community_vectorstores_chroma.Chroma.html#constructor)
71
+ *
72
+ * <details open>
73
+ * <summary><strong>Instantiate</strong></summary>
74
+ *
75
+ * ```typescript
76
+ * import { Chroma } from '@langchain/community/vectorstores/chroma';
77
+ * import { OpenAIEmbeddings } from '@langchain/openai';
78
+ *
79
+ * const vectorStore = new Chroma(
80
+ * new OpenAIEmbeddings(),
81
+ * {
82
+ * collectionName: "foo",
83
+ * url: "http://localhost:8000", // URL of the Chroma server
84
+ * }
85
+ * );
86
+ * ```
87
+ * </details>
88
+ *
89
+ * <br />
90
+ *
91
+ * <details>
92
+ * <summary><strong>Add documents</strong></summary>
93
+ *
94
+ * ```typescript
95
+ * import { Document } from '@langchain/core/documents';
96
+ *
97
+ * const document1 = new Document({ pageContent: "foo", metadata: { baz: "bar" } });
98
+ * const document2 = new Document({ pageContent: "thud", metadata: { bar: "baz" } });
99
+ * const document3 = new Document({ pageContent: "i will be deleted :(" });
100
+ *
101
+ * const documents = [document1, document2, document3];
102
+ * const ids = ["1", "2", "3"];
103
+ * await vectorStore.addDocuments(documents, { ids });
104
+ * ```
105
+ * </details>
106
+ *
107
+ * <br />
108
+ *
109
+ * <details>
110
+ * <summary><strong>Delete documents</strong></summary>
111
+ *
112
+ * ```typescript
113
+ * await vectorStore.delete({ ids: ["3"] });
114
+ * ```
115
+ * </details>
116
+ *
117
+ * <br />
118
+ *
119
+ * <details>
120
+ * <summary><strong>Similarity search</strong></summary>
121
+ *
122
+ * ```typescript
123
+ * const results = await vectorStore.similaritySearch("thud", 1);
124
+ * for (const doc of results) {
125
+ * console.log(`* ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
126
+ * }
127
+ * // Output: * thud [{"baz":"bar"}]
128
+ * ```
129
+ * </details>
130
+ *
131
+ * <br />
132
+ *
133
+ *
134
+ * <details>
135
+ * <summary><strong>Similarity search with filter</strong></summary>
136
+ *
137
+ * ```typescript
138
+ * const resultsWithFilter = await vectorStore.similaritySearch("thud", 1, { baz: "bar" });
139
+ *
140
+ * for (const doc of resultsWithFilter) {
141
+ * console.log(`* ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
142
+ * }
143
+ * // Output: * foo [{"baz":"bar"}]
144
+ * ```
145
+ * </details>
146
+ *
147
+ * <br />
148
+ *
149
+ *
150
+ * <details>
151
+ * <summary><strong>Similarity search with score</strong></summary>
152
+ *
153
+ * ```typescript
154
+ * const resultsWithScore = await vectorStore.similaritySearchWithScore("qux", 1);
155
+ * for (const [doc, score] of resultsWithScore) {
156
+ * console.log(`* [SIM=${score.toFixed(6)}] ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
157
+ * }
158
+ * // Output: * [SIM=0.000000] qux [{"bar":"baz","baz":"bar"}]
159
+ * ```
160
+ * </details>
161
+ *
162
+ * <br />
163
+ *
164
+ * <details>
165
+ * <summary><strong>As a retriever</strong></summary>
166
+ *
167
+ * ```typescript
168
+ * const retriever = vectorStore.asRetriever({
169
+ * searchType: "mmr",
170
+ * k: 1,
171
+ * });
172
+ * const resultAsRetriever = await retriever.invoke("thud");
173
+ * console.log(resultAsRetriever);
174
+ *
175
+ * // Output: [Document({ metadata: { "baz":"bar" }, pageContent: "thud" })]
176
+ * ```
177
+ * </details>
178
+ *
179
+ * <br />
52
180
*/
53
181
export class Chroma extends VectorStore {
54
182
declare FilterType : Where ;
0 commit comments