You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: knowledge/langchain.mdx
+17-4Lines changed: 17 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,25 @@ sidebarTitle: LangChain
4
4
---
5
5
6
6
The **LangchainKnowledgeBase** allows us to use a LangChain retriever or vector store as a knowledge base.
7
-
7
+
Using ChromaDB as the vectorDB in this example.
8
8
## Usage
9
9
10
10
```shell
11
11
pip install langchain
12
12
```
13
13
14
+
```shell
15
+
pip install -qU "langchain-chroma>=0.1.2"
16
+
```
17
+
14
18
```python langchain_kb.py
15
19
from phi.agent import Agent
16
20
from phi.knowledge.langchain import LangChainKnowledgeBase
17
21
18
-
fromlangchain.embeddingsimport OpenAIEmbeddings
22
+
fromlangchain_openaiimport OpenAIEmbeddings
19
23
from langchain.document_loaders import TextLoader
20
24
from langchain.text_splitter import CharacterTextSplitter
21
-
fromlangchain.vectorstoresimport Chroma
25
+
fromlangchain_chromaimport Chroma
22
26
23
27
chroma_db_dir ="./chroma_db"
24
28
@@ -35,7 +39,13 @@ def load_vector_store():
35
39
36
40
37
41
# -*- Get the vectordb
38
-
db = Chroma(embedding_function=OpenAIEmbeddings(), persist_directory=str(chroma_db_dir))
42
+
db = Chroma(
43
+
collection_name="your_collection_name",
44
+
persist_directory=chroma_db_dir,
45
+
embedding_function=OpenAIEmbeddings(),
46
+
47
+
)
48
+
39
49
# -*- Create a retriever from the vector store
40
50
retriever = db.as_retriever()
41
51
@@ -53,3 +63,6 @@ conv.print_response("What did the president say about technology?")
53
63
|`retriever`|`Any`|`None`| LangChain retriever. |
54
64
|`vectorstore`|`Any`|`None`| LangChain vector store used to create a retriever. |
55
65
|`search_kwargs`|`dict`|`None`| Search kwargs when creating a retriever using the langchain vector store. |
66
+
67
+
68
+
You can also find more information about updates here [LangChain Chroma Vector Store Documentation](https://python.langchain.com/docs/integrations/vectorstores/chroma/)
0 commit comments