mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-21 06:33:41 +00:00
- **Description:** This PR updates the internal documentation link for the RAG tutorials to reflect the updated path. Previously, the link pointed to the root `/docs/tutorials/`, which was generic. It now correctly routes to the RAG-specific tutorial page. - **Issue:** N/A - **Dependencies:** None - **Twitter handle:** N/A
679 lines
19 KiB
Plaintext
679 lines
19 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "683953b3",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Chroma\n",
|
|
"\n",
|
|
"This notebook covers how to get started with the `Chroma` vector store.\n",
|
|
"\n",
|
|
">[Chroma](https://docs.trychroma.com/getting-started) is a AI-native open-source vector database focused on developer productivity and happiness. Chroma is licensed under Apache 2.0. View the full docs of `Chroma` at [this page](https://docs.trychroma.com/reference/py-collection), and find the API reference for the LangChain integration at [this page](https://python.langchain.com/api_reference/chroma/vectorstores/langchain_chroma.vectorstores.Chroma.html).\n",
|
|
"\n",
|
|
":::info Chroma Cloud\n",
|
|
"\n",
|
|
"Chroma Cloud powers serverless vector and full-text search. It's extremely fast, cost-effective, scalable and painless. Create a DB and try it out in under 30 seconds with $5 of free credits.\n",
|
|
"\n",
|
|
"[Get started with Chroma Cloud](https://trychroma.com/signup)\n",
|
|
":::\n",
|
|
"\n",
|
|
"## Setup\n",
|
|
"\n",
|
|
"To access `Chroma` vector stores you'll need to install the `langchain-chroma` integration package."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "83a43688",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"pip install -qU \"langchain-chroma>=0.1.2\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2b5ffbf8",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Credentials\n",
|
|
"\n",
|
|
"You can use the `Chroma` vector store without any credentials, simply installing the package above is enough!\n",
|
|
"\n",
|
|
"If you are a [Chroma Cloud](https://trychroma.com/signup) user, set your `CHROMA_TENANT`, `CHROMA_DATABASE`, and `CHROMA_API_KEY` environment variables.\n",
|
|
"\n",
|
|
"When you install the `chromadb` package you also get access to the Chroma CLI, which can set these for you. First, [login](https://docs.trychroma.com/docs/cli/login) via the CLI, and then use the [`connect` command](https://docs.trychroma.com/docs/cli/db):\n",
|
|
"\n",
|
|
"```bash\n",
|
|
"chroma db connect [db_name] --env-file\n",
|
|
"```"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "cd17cfed",
|
|
"metadata": {},
|
|
"source": [
|
|
"If you want to get best in-class automated tracing of your model calls you can also set your [LangSmith](https://docs.smith.langchain.com/) API key by uncommenting below:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "dd7e1243",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# os.environ[\"LANGSMITH_API_KEY\"] = getpass.getpass(\"Enter your LangSmith API key: \")\n",
|
|
"# os.environ[\"LANGSMITH_TRACING\"] = \"true\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f47f73f4",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Initialization\n",
|
|
"\n",
|
|
"### Basic Initialization \n",
|
|
"\n",
|
|
"Below is a basic initialization, including the use of a directory to save the data locally.\n",
|
|
"\n",
|
|
"import EmbeddingTabs from \"@theme/EmbeddingTabs\";\n",
|
|
"\n",
|
|
"<EmbeddingTabs/>\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d3ed0a9a",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# | output: false\n",
|
|
"# | echo: false\n",
|
|
"from langchain_openai import OpenAIEmbeddings\n",
|
|
"\n",
|
|
"embeddings = OpenAIEmbeddings(model=\"text-embedding-3-large\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c6a43e25-227c-4e89-909f-3654fe2710fc",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Running Locally (In-Memory)\n",
|
|
"\n",
|
|
"You can get a Chroma server running in memory by simply instantiating a `Chroma` instance with a collection name and your embeddings provider:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "3ea11a7b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from langchain_chroma import Chroma\n",
|
|
"\n",
|
|
"vector_store = Chroma(\n",
|
|
" collection_name=\"example_collection\",\n",
|
|
" embedding_function=embeddings,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "92d04cda-e8cc-48aa-9680-470304e3ff4c",
|
|
"metadata": {},
|
|
"source": [
|
|
"If you don't need data persistence, this is a great option for experimenting while building your AI application with Langchain."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ad6adc53-4b3f-458e-8e2e-efcc3f99f0c5",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Running Locally (with Data Persistence)\n",
|
|
"\n",
|
|
"You can provide the `persist_directory` argument to save your data across multiple runs of your program:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5a858e77-fd6d-44f0-840f-8f71eaeae6f7",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from langchain_chroma import Chroma\n",
|
|
"\n",
|
|
"vector_store = Chroma(\n",
|
|
" collection_name=\"example_collection\",\n",
|
|
" embedding_function=embeddings,\n",
|
|
" persist_directory=\"./chroma_langchain_db\",\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "47bf272e-af0b-450e-8a86-3e8292273cde",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Connecting to a Chroma Server\n",
|
|
"\n",
|
|
"If you have a Chroma server running locally, or you have [deployed](https://docs.trychroma.com/guides/deploy/client-server-mode) one yourself, you can connect to it by providing the `host` argument.\n",
|
|
"\n",
|
|
"For example, you can start a Chroma server running locally with `chroma run`, and then connect it with `host='localhost'`:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "679d619f-b8ee-4abb-8ac0-77ec859ddff1",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from langchain_chroma import Chroma\n",
|
|
"\n",
|
|
"vector_store = Chroma(\n",
|
|
" collection_name=\"example_collection\",\n",
|
|
" embedding_function=embeddings,\n",
|
|
" host=\"localhost\",\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e3c06ed9-c010-4764-bd6e-2a0c71201d5b",
|
|
"metadata": {},
|
|
"source": [
|
|
"For other deployments you can use the `port`, `ssl`, and `headers` arguments to customize your connection."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0f3238e1-ca57-482d-878d-b09bd2c8015c",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Chroma Cloud\n",
|
|
"\n",
|
|
"Chroma Cloud users can also build with Langchain. Provide your `Chroma` instance with your Chroma Cloud API key, tenant, and DB name:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e080d2d2-c501-467e-9842-e2045d86cdb5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from langchain_chroma import Chroma\n",
|
|
"\n",
|
|
"vector_store = Chroma(\n",
|
|
" collection_name=\"example_collection\",\n",
|
|
" embedding_function=embeddings,\n",
|
|
" chroma_cloud_api_key=os.getenv(\"CHROMA_API_KEY\"),\n",
|
|
" tenant=os.getenv(\"CHROMA_TENANT\"),\n",
|
|
" database=os.getenv(\"CHROMA_DATABASE\"),\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ccb62a8c",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Initialization from client\n",
|
|
"\n",
|
|
"You can also initialize from a `Chroma` client, which is particularly useful if you want easier access to the underlying database."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "38e9f893-60df-4a4f-b570-2d1c463cc1e4",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Running Locally (In-Memory)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "09bfb62f-7c6b-43d3-a69a-0601899c6942",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import chromadb\n",
|
|
"\n",
|
|
"client = chromadb.Client()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f3eac2de-0cca-4d57-b67d-04cc78bb59c1",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Running Locally (with Data Persistence)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "ffc7f2ad-0d6c-4911-a4cf-a82bf7649478",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import chromadb\n",
|
|
"\n",
|
|
"client = chromadb.PersistentClient(path=\"./chroma_langchain_db\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "41cc98d5-94f3-4a2f-903e-61c4a38d8f9c",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Connecting to a Chroma Server\n",
|
|
"\n",
|
|
"For example, if you are running a Chroma server locally (using `chroma run`):"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "bb5828e3-c0a5-4f97-8d2e-23d82257743e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import chromadb\n",
|
|
"\n",
|
|
"client = chromadb.HttpClient(host=\"localhost\", port=8000, ssl=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "254ecfdb-f247-4a3d-a52a-e515b17b7ba2",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Chroma Cloud"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "fbbf8042-7ae7-4221-96e3-dc2048dd0f45",
|
|
"metadata": {},
|
|
"source": [
|
|
"After setting your `CHROMA_API_KEY`, `CHROMA_TENANT`, and `CHROMA_DATABASE`, you can simply instantiate:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "89e86a01-a347-4041-a4a1-01eecd299235",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import chromadb\n",
|
|
"\n",
|
|
"client = chromadb.CloudClient()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "8fdd8bbb-45ab-43d8-bdc1-7220b14cfc52",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Access your Chroma DB"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6da21a1a-8d0d-4a4b-bac5-008839e89540",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"collection = client.get_or_create_collection(\"collection_name\")\n",
|
|
"collection.add(ids=[\"1\", \"2\", \"3\"], documents=[\"a\", \"b\", \"c\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "581906ba-8082-450c-a3c4-19284539980b",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Create a Chroma Vectorstore"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "3fe4457f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"vector_store_from_client = Chroma(\n",
|
|
" client=client,\n",
|
|
" collection_name=\"collection_name\",\n",
|
|
" embedding_function=embeddings,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "9d037340",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Manage vector store\n",
|
|
"\n",
|
|
"Once you have created your vector store, we can interact with it by adding and deleting different items.\n",
|
|
"\n",
|
|
"### Add items to vector store\n",
|
|
"\n",
|
|
"We can add items to our vector store by using the `add_documents` function."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "da279339",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from uuid import uuid4\n",
|
|
"\n",
|
|
"from langchain_core.documents import Document\n",
|
|
"\n",
|
|
"document_1 = Document(\n",
|
|
" page_content=\"I had chocolate chip pancakes and scrambled eggs for breakfast this morning.\",\n",
|
|
" metadata={\"source\": \"tweet\"},\n",
|
|
" id=1,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_2 = Document(\n",
|
|
" page_content=\"The weather forecast for tomorrow is cloudy and overcast, with a high of 62 degrees.\",\n",
|
|
" metadata={\"source\": \"news\"},\n",
|
|
" id=2,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_3 = Document(\n",
|
|
" page_content=\"Building an exciting new project with LangChain - come check it out!\",\n",
|
|
" metadata={\"source\": \"tweet\"},\n",
|
|
" id=3,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_4 = Document(\n",
|
|
" page_content=\"Robbers broke into the city bank and stole $1 million in cash.\",\n",
|
|
" metadata={\"source\": \"news\"},\n",
|
|
" id=4,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_5 = Document(\n",
|
|
" page_content=\"Wow! That was an amazing movie. I can't wait to see it again.\",\n",
|
|
" metadata={\"source\": \"tweet\"},\n",
|
|
" id=5,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_6 = Document(\n",
|
|
" page_content=\"Is the new iPhone worth the price? Read this review to find out.\",\n",
|
|
" metadata={\"source\": \"website\"},\n",
|
|
" id=6,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_7 = Document(\n",
|
|
" page_content=\"The top 10 soccer players in the world right now.\",\n",
|
|
" metadata={\"source\": \"website\"},\n",
|
|
" id=7,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_8 = Document(\n",
|
|
" page_content=\"LangGraph is the best framework for building stateful, agentic applications!\",\n",
|
|
" metadata={\"source\": \"tweet\"},\n",
|
|
" id=8,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_9 = Document(\n",
|
|
" page_content=\"The stock market is down 500 points today due to fears of a recession.\",\n",
|
|
" metadata={\"source\": \"news\"},\n",
|
|
" id=9,\n",
|
|
")\n",
|
|
"\n",
|
|
"document_10 = Document(\n",
|
|
" page_content=\"I have a bad feeling I am going to get deleted :(\",\n",
|
|
" metadata={\"source\": \"tweet\"},\n",
|
|
" id=10,\n",
|
|
")\n",
|
|
"\n",
|
|
"documents = [\n",
|
|
" document_1,\n",
|
|
" document_2,\n",
|
|
" document_3,\n",
|
|
" document_4,\n",
|
|
" document_5,\n",
|
|
" document_6,\n",
|
|
" document_7,\n",
|
|
" document_8,\n",
|
|
" document_9,\n",
|
|
" document_10,\n",
|
|
"]\n",
|
|
"uuids = [str(uuid4()) for _ in range(len(documents))]\n",
|
|
"\n",
|
|
"vector_store.add_documents(documents=documents, ids=uuids)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "7add6366",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Update items in vector store\n",
|
|
"\n",
|
|
"Now that we have added documents to our vector store, we can update existing documents by using the `update_documents` function. "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ef5dbd1e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"updated_document_1 = Document(\n",
|
|
" page_content=\"I had chocolate chip pancakes and fried eggs for breakfast this morning.\",\n",
|
|
" metadata={\"source\": \"tweet\"},\n",
|
|
" id=1,\n",
|
|
")\n",
|
|
"\n",
|
|
"updated_document_2 = Document(\n",
|
|
" page_content=\"The weather forecast for tomorrow is sunny and warm, with a high of 82 degrees.\",\n",
|
|
" metadata={\"source\": \"news\"},\n",
|
|
" id=2,\n",
|
|
")\n",
|
|
"\n",
|
|
"vector_store.update_document(document_id=uuids[0], document=updated_document_1)\n",
|
|
"# You can also update multiple documents at once\n",
|
|
"vector_store.update_documents(\n",
|
|
" ids=uuids[:2], documents=[updated_document_1, updated_document_2]\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "74b9a13a",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Delete items from vector store\n",
|
|
"\n",
|
|
"We can also delete items from our vector store as follows:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "56f17791",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"vector_store.delete(ids=uuids[-1])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "213acf08",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Query vector store\n",
|
|
"\n",
|
|
"Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent. \n",
|
|
"\n",
|
|
"### Query directly\n",
|
|
"\n",
|
|
"#### Similarity search\n",
|
|
"\n",
|
|
"Performing a simple similarity search can be done as follows:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e2b96fcf",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"results = vector_store.similarity_search(\n",
|
|
" \"LangChain provides abstractions to make working with LLMs easy\",\n",
|
|
" k=2,\n",
|
|
" filter={\"source\": \"tweet\"},\n",
|
|
")\n",
|
|
"for res in results:\n",
|
|
" print(f\"* {res.page_content} [{res.metadata}]\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "cdd117ea",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Similarity search with score\n",
|
|
"\n",
|
|
"If you want to execute a similarity search and receive the corresponding scores you can run:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2768a331",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"results = vector_store.similarity_search_with_score(\n",
|
|
" \"Will it be hot tomorrow?\", k=1, filter={\"source\": \"news\"}\n",
|
|
")\n",
|
|
"for res, score in results:\n",
|
|
" print(f\"* [SIM={score:3f}] {res.page_content} [{res.metadata}]\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "92b436c8",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Search by vector\n",
|
|
"\n",
|
|
"You can also search by vector:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "8ea434a5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"results = vector_store.similarity_search_by_vector(\n",
|
|
" embedding=embeddings.embed_query(\"I love green eggs and ham!\"), k=1\n",
|
|
")\n",
|
|
"for doc in results:\n",
|
|
" print(f\"* {doc.page_content} [{doc.metadata}]\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "9c1c1e6f",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Other search methods\n",
|
|
"\n",
|
|
"There are a variety of other search methods that are not covered in this notebook, such as MMR search or searching by vector. For a full list of the search abilities available for `AstraDBVectorStore` check out the [API reference](https://python.langchain.com/api_reference/astradb/vectorstores/langchain_astradb.vectorstores.AstraDBVectorStore.html).\n",
|
|
"\n",
|
|
"### Query by turning into retriever\n",
|
|
"\n",
|
|
"You can also transform the vector store into a retriever for easier usage in your chains. For more information on the different search types and kwargs you can pass, please visit the API reference [here](https://python.langchain.com/api_reference/chroma/vectorstores/langchain_chroma.vectorstores.Chroma.html#langchain_chroma.vectorstores.Chroma.as_retriever)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7b6f7867",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"retriever = vector_store.as_retriever(\n",
|
|
" search_type=\"mmr\", search_kwargs={\"k\": 1, \"fetch_k\": 5}\n",
|
|
")\n",
|
|
"retriever.invoke(\"Stealing from the bank is a crime\", filter={\"source\": \"news\"})"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "a2b7b73c",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Usage for retrieval-augmented generation\n",
|
|
"\n",
|
|
"For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:\n",
|
|
"\n",
|
|
"- [Tutorials](/docs/tutorials/rag)\n",
|
|
"- [How-to: Question and answer with RAG](https://python.langchain.com/docs/how_to/#qa-with-rag)\n",
|
|
"- [Retrieval conceptual docs](https://python.langchain.com/docs/concepts/retrieval)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "fed28359",
|
|
"metadata": {},
|
|
"source": [
|
|
"## API reference\n",
|
|
"\n",
|
|
"For detailed documentation of all `Chroma` vector store features and configurations head to the API reference: https://python.langchain.com/api_reference/chroma/vectorstores/langchain_chroma.vectorstores.Chroma.html"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.0"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|