@@ -18,18 +18,45 @@ As of version `0.5.x` Chroma offers a built-in two-way adapter to convert Langch
18
18
embeddings that can be used by both LC and Chroma. Implementation can be
19
19
found [ here] ( https://github.com/chroma-core/chroma/blob/main/chromadb/utils/embedding_functions/chroma_langchain_embedding_function.py ) .
20
20
21
- ``` python
22
- # pip install chromadb langchain langchain-huggingface langchain-chroma
23
- import chromadb
24
- from chromadb.utils.embedding_functions import create_langchain_embedding
25
- from langchain_huggingface import HuggingFaceEmbeddings
21
+ === "HuggingFace"
26
22
27
- langchain_embeddings = HuggingFaceEmbeddings( model_name = " all-MiniLM-L6-v2 " )
23
+ Find out more about Langchain's HuggingFace embeddings [here](https://python.langchain.com/docs/integrations/platforms/huggingface/#embedding-models).
28
24
29
- ef = create_langchain_embedding(langchain_embeddings)
30
- client = chromadb.PersistentClient(path = " /test_folder_1" )
31
- collection = client.get_or_create_collection(name = " name_1" , embedding_function = ef)
32
- ```
25
+ ```python
26
+ # pip install chromadb langchain langchain-huggingface langchain-chroma
27
+ import chromadb
28
+ from chromadb.utils.embedding_functions import create_langchain_embedding
29
+ from langchain_huggingface import HuggingFaceEmbeddings
30
+
31
+ langchain_embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
32
+
33
+ ef = create_langchain_embedding(langchain_embeddings)
34
+ client = chromadb.PersistentClient(path="./chroma-data")
35
+ collection = client.get_or_create_collection(name="my_collection", embedding_function=ef)
36
+
37
+ collection.add(ids=["1"],documents=["test document goes here"])
38
+ ```
39
+
40
+ === "OpenAI"
41
+
42
+ Find out more about Langchain's OpenAI embeddings [here](https://python.langchain.com/docs/integrations/text_embedding/openai/).
43
+
44
+ ```python
45
+ import chromadb
46
+ from chromadb.utils.embedding_functions import create_langchain_embedding
47
+ from langchain_openai import OpenAIEmbeddings
48
+ from google.colab import userdata
49
+
50
+ langchain_embeddings = OpenAIEmbeddings(
51
+ model="text-embedding-3-large",
52
+ api_key=os.environ["OPENAI_API_KEY"],
53
+ )
54
+ ef = create_langchain_embedding(langchain_embeddings)
55
+ client = chromadb.PersistentClient(path="/chroma-data")
56
+ collection = client.get_or_create_collection(name="my_collection", embedding_function=ef)
57
+
58
+ collection.add(ids=["1"],documents=["test document goes here"])
59
+ ```
33
60
34
61
### Custom Adapter
35
62
0 commit comments