seansullivan/Langchain-Docs huggingface dataset:
## Upstage

[Upstage](https://upstage.ai/) is a leading artificial intelligence (AI) company specializing in delivering above-human-grade performance LLM components.

## Solar LLM[​](#solar-llm "Direct link to Solar LLM")

**Solar Mini Chat** is a fast yet powerful advanced large language model focusing on English and Korean. It has been specifically fine-tuned for multi-turn chat purposes, showing enhanced performance across a wide range of natural language processing tasks, like multi-turn conversation or tasks that require an understanding of long contexts, such as RAG (Retrieval-Augmented Generation), compared to other models of a similar size. This fine-tuning equips it with the ability to handle longer conversations more effectively, making it particularly adept for interactive applications.

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

Install `langchain-upstage` package:

```
pip install -qU langchain-core langchain-upstage
```

Get an [access token](https://console.upstage.ai/) and set it as an environment variable (`UPSTAGE_API_KEY`)

## Upstage LangChain integrations[​](#upstage-langchain-integrations "Direct link to Upstage LangChain integrations")

| API | Description | Import | Example usage |
| --- | --- | --- | --- |
| Chat | Build assistants using Solar Mini Chat | `from langchain_upstage import ChatUpstage` | [Go](https://python.langchain.com/docs/integrations/chat/upstage/) |
| Text Embedding | Embed strings to vectors | `from langchain_upstage import UpstageEmbeddings` | [Go](https://python.langchain.com/docs/integrations/text_embedding/upstage/) |

See [documentations](https://developers.upstage.ai/) for more details about the features.

## Quick Examples[​](#quick-examples "Direct link to Quick Examples")

### Environment Setup[​](#environment-setup "Direct link to Environment Setup")

```
import osos.environ["UPSTAGE_API_KEY"] = "YOUR_API_KEY"
```

### Chat[​](#chat "Direct link to Chat")

```
from langchain_upstage import ChatUpstagechat = ChatUpstage()response = chat.invoke("Hello, how are you?")print(response)
```

### Text embedding[​](#text-embedding "Direct link to Text embedding")

```
from langchain_upstage import UpstageEmbeddingsembeddings = UpstageEmbeddings()doc_result = embeddings.embed_documents(    ["Sam is a teacher.", "This is another document"])print(doc_result)query_result = embeddings.embed_query("What does Sam do?")print(query_result)
```
Upstash offers developers serverless databases and messaging platforms to build powerful applications without having to worry about the operational complexity of running databases at scale.

All of Upstash-LangChain integrations are based on `upstash-redis` Python SDK being utilized as wrappers for LangChain. This SDK utilizes Upstash Redis DB by giving UPSTASH\_REDIS\_REST\_URL and UPSTASH\_REDIS\_REST\_TOKEN parameters from the console. One significant advantage of this is that, this SDK uses a REST API. This means, you can run this in serverless platforms, edge or any platform that does not support TCP connections.

```
import langchainfrom upstash_redis import RedisURL = "<UPSTASH_REDIS_REST_URL>"TOKEN = "<UPSTASH_REDIS_REST_TOKEN>"langchain.llm_cache = UpstashRedisCache(redis_=Redis(url=URL, token=TOKEN))
```
The vector store is a simple wrapper around VDMS. It provides a simple interface to store and retrieve data.

```
from langchain_community.document_loaders import TextLoaderfrom langchain.text_splitter import CharacterTextSplitterloader = TextLoader("./state_of_the_union.txt")documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=0)docs = text_splitter.split_documents(documents)from langchain_community.vectorstores import VDMSfrom langchain_community.vectorstores.vdms import VDMS_Clientfrom langchain_community.embeddings.huggingface import HuggingFaceEmbeddingsclient = VDMS_Client("localhost", 55555)vectorstore = VDMS.from_documents(    docs,    client=client,    collection_name="langchain-demo",    embedding_function=HuggingFaceEmbeddings(),    engine="FaissFlat"    distance_strategy="L2",)query = "What did the president say about Ketanji Brown Jackson"results = vectorstore.similarity_search(query)
```
## Vespa

> [Vespa](https://vespa.ai/) is a fully featured search engine and vector database. It supports vector search (ANN), lexical search, and search in structured data, all in the same query.

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

## Retriever[​](#retriever "Direct link to Retriever")

See a [usage example](https://python.langchain.com/docs/integrations/retrievers/vespa/).

```
from langchain.retrievers import VespaRetriever
```

* * *

#### Help us out by providing feedback on this documentation page:
`USearch's` base functionality is identical to `FAISS`, and the interface should look familiar if you have ever investigated Approximate Nearest Neighbors search. `USearch` and `FAISS` both employ `HNSW` algorithm, but they differ significantly in their design principles. `USearch` is compact and broadly compatible with FAISS without sacrificing performance, with a primary focus on user-defined metrics and fewer dependencies.

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

We need to install `usearch` python package.

```
from langchain_community.vectorstores import USearch
```
## BM25

> [BM25 (Wikipedia)](https://en.wikipedia.org/wiki/Okapi_BM25) also known as the `Okapi BM25`, is a ranking function used in information retrieval systems to estimate the relevance of documents to a given search query.
> 
> `BM25Retriever` retriever uses the [`rank_bm25`](https://github.com/dorianbrown/rank_bm25) package.

```
%pip install --upgrade --quiet  rank_bm25
```

```
from langchain_community.retrievers import BM25Retriever
```

## Create New Retriever with Texts[​](#create-new-retriever-with-texts "Direct link to Create New Retriever with Texts")

```
retriever = BM25Retriever.from_texts(["foo", "bar", "world", "hello", "foo bar"])
```

## Create a New Retriever with Documents[​](#create-a-new-retriever-with-documents "Direct link to Create a New Retriever with Documents")

You can now create a new retriever with the documents you created.

```
from langchain_core.documents import Documentretriever = BM25Retriever.from_documents(    [        Document(page_content="foo"),        Document(page_content="bar"),        Document(page_content="world"),        Document(page_content="hello"),        Document(page_content="foo bar"),    ])
```

## Use Retriever[​](#use-retriever "Direct link to Use Retriever")

We can now use the retriever!

```
result = retriever.get_relevant_documents("foo")
```

```
[Document(page_content='foo', metadata={}), Document(page_content='foo bar', metadata={}), Document(page_content='hello', metadata={}), Document(page_content='world', metadata={})]
```

* * *

#### Help us out by providing feedback on this documentation page:
[Chaindesk platform](https://docs.chaindesk.ai/introduction) brings data from anywhere (Datsources: Text, PDF, Word, PowerPpoint, Excel, Notion, Airtable, Google Sheets, etc..) into Datastores (container of multiple Datasources). Then your Datastores can be connected to ChatGPT via Plugins or any other Large Langue Model (LLM) via the `Chaindesk API`.

First, you will need to sign up for Chaindesk, create a datastore, add some data and get your datastore api endpoint url. You need the [API Key](https://docs.chaindesk.ai/api-reference/authentication).

Now that our index is set up, we can set up a retriever and start querying it.

```
[Document(page_content='✨ Made with DaftpageOpen main menuPricingTemplatesLoginSearchHelpGetting StartedFeaturesAffiliate ProgramGetting StartedDaftpage is a new type of website builder that works like a doc.It makes website building easy, fun and offers tons of powerful features for free. Just type / in your page to get started!DaftpageCopyright © 2022 Daftpage, Inc.All rights reserved.ProductPricingTemplatesHelp & SupportHelp CenterGetting startedBlogCompanyAboutRoadmapTwitterAffiliate Program👾 Discord', metadata={'source': 'https:/daftpage.com/help/getting-started', 'score': 0.8697265}), Document(page_content="✨ Made with DaftpageOpen main menuPricingTemplatesLoginSearchHelpGetting StartedFeaturesAffiliate ProgramHelp CenterWelcome to Daftpage’s help center—the one-stop shop for learning everything about building websites with Daftpage.Daftpage is the simplest way to create websites for all purposes in seconds. Without knowing how to code, and for free!Get StartedDaftpage is a new type of website builder that works like a doc.It makes website building easy, fun and offers tons of powerful features for free. Just type / in your page to get started!Start here✨ Create your first site🧱 Add blocks🚀 PublishGuides🔖 Add a custom domainFeatures🔥 Drops🎨 Drawings👻 Ghost mode💀 Skeleton modeCant find the answer you're looking for?mail us at support@daftpage.comJoin the awesome Daftpage community on: 👾 DiscordDaftpageCopyright © 2022 Daftpage, Inc.All rights reserved.ProductPricingTemplatesHelp & SupportHelp CenterGetting startedBlogCompanyAboutRoadmapTwitterAffiliate Program👾 Discord", metadata={'source': 'https:/daftpage.com/help', 'score': 0.86570895}), Document(page_content=" is the simplest way to create websites for all purposes in seconds. Without knowing how to code, and for free!Get StartedDaftpage is a new type of website builder that works like a doc.It makes website building easy, fun and offers tons of powerful features for free. Just type / in your page to get started!Start here✨ Create your first site🧱 Add blocks🚀 PublishGuides🔖 Add a custom domainFeatures🔥 Drops🎨 Drawings👻 Ghost mode💀 Skeleton modeCant find the answer you're looking for?mail us at support@daftpage.comJoin the awesome Daftpage community on: 👾 DiscordDaftpageCopyright © 2022 Daftpage, Inc.All rights reserved.ProductPricingTemplatesHelp & SupportHelp CenterGetting startedBlogCompanyAboutRoadmapTwitterAffiliate Program👾 Discord", metadata={'source': 'https:/daftpage.com/help', 'score': 0.8645384})]
```
Plugins allow `ChatGPT` to do things like: - Retrieve real-time information; e.g., sports scores, stock prices, the latest news, etc. - Retrieve knowledge-base information; e.g., company docs, personal notes, etc. - Perform actions on behalf of the user; e.g., booking a flight, ordering food, etc.

This notebook shows how to use the ChatGPT Retriever Plugin within LangChain.

```
# STEP 1: Load# Load documents using LangChain's DocumentLoaders# This is from https://langchain.readthedocs.io/en/latest/modules/document_loaders/examples/csv.htmlfrom langchain_community.document_loaders import CSVLoaderloader = CSVLoader(    file_path="../../document_loaders/examples/example_data/mlb_teams_2012.csv")data = loader.load()# STEP 2: Convert# Convert Document to format expected by https://github.com/openai/chatgpt-retrieval-pluginimport jsonfrom typing import Listfrom langchain_community.docstore.document import Documentdef write_json(path: str, documents: List[Document]) -> None:    results = [{"text": doc.page_content} for doc in documents]    with open(path, "w") as f:        json.dump(results, f, indent=2)write_json("foo.json", data)# STEP 3: Use# Ingest this as you would any other json file in https://github.com/openai/chatgpt-retrieval-plugin/tree/main/scripts/process_json
```

Okay, so we’ve created the ChatGPT Retriever Plugin, but how do we actually use it?

The below code walks through how to do that.

We want to use `ChatGPTPluginRetriever` so we have to get the OpenAI API Key.

```
[Document(page_content="This is Alice's phone number: 123-456-7890", lookup_str='', metadata={'id': '456_0', 'metadata': {'source': 'email', 'source_id': '567', 'url': None, 'created_at': '1609592400.0', 'author': 'Alice', 'document_id': '456'}, 'embedding': None, 'score': 0.925571561}, lookup_index=0), Document(page_content='This is a document about something', lookup_str='', metadata={'id': '123_0', 'metadata': {'source': 'file', 'source_id': 'https://example.com/doc1', 'url': 'https://example.com/doc1', 'created_at': '1609502400.0', 'author': 'Alice', 'document_id': '123'}, 'embedding': None, 'score': 0.6987589}, lookup_index=0), Document(page_content='Team: Angels "Payroll (millions)": 154.49 "Wins": 89', lookup_str='', metadata={'id': '59c2c0c1-ae3f-4272-a1da-f44a723ea631_0', 'metadata': {'source': None, 'source_id': None, 'url': None, 'created_at': None, 'author': None, 'document_id': '59c2c0c1-ae3f-4272-a1da-f44a723ea631'}, 'embedding': None, 'score': 0.697888613}, lookup_index=0)]
```
## Dria

> [Dria](https://dria.co/) is a hub of public RAG models for developers to both contribute and utilize a shared embedding lake. This notebook demonstrates how to use the `Dria API` for data retrieval tasks.

## Installation

Ensure you have the `dria` package installed. You can install it using pip:

```
%pip install --upgrade --quiet dria
```

## Configure API Key

Set up your Dria API key for access.

```
import osos.environ["DRIA_API_KEY"] = "DRIA_API_KEY"
```

## Initialize Dria Retriever

Create an instance of `DriaRetriever`.

```
from langchain.retrievers import DriaRetrieverapi_key = os.getenv("DRIA_API_KEY")retriever = DriaRetriever(api_key=api_key)
```

## **Create Knowledge Base**

Create a knowledge on [Dria’s Knowledge Hub](https://dria.co/knowledge)

```
contract_id = retriever.create_knowledge_base(    name="France's AI Development",    embedding=DriaRetriever.models.jina_embeddings_v2_base_en.value,    category="Artificial Intelligence",    description="Explore the growth and contributions of France in the field of Artificial Intelligence.",)
```

## Add Data

Load data into your Dria knowledge base.

```
texts = [    "The first text to add to Dria.",    "Another piece of information to store.",    "More data to include in the Dria knowledge base.",]ids = retriever.add_texts(texts)print("Data added with IDs:", ids)
```

## Retrieve Data

Use the retriever to find relevant documents given a query.

```
query = "Find information about Dria."result = retriever.get_relevant_documents(query)for doc in result:    print(doc)
```
## ElasticSearch BM25

> [Elasticsearch](https://www.elastic.co/elasticsearch/) is a distributed, RESTful search and analytics engine. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.

> In information retrieval, [Okapi BM25](https://en.wikipedia.org/wiki/Okapi_BM25) (BM is an abbreviation of best matching) is a ranking function used by search engines to estimate the relevance of documents to a given search query. It is based on the probabilistic retrieval framework developed in the 1970s and 1980s by Stephen E. Robertson, Karen Spärck Jones, and others.

> The name of the actual ranking function is BM25. The fuller name, Okapi BM25, includes the name of the first system to use it, which was the Okapi information retrieval system, implemented at London’s City University in the 1980s and 1990s. BM25 and its newer variants, e.g. BM25F (a version of BM25 that can take document structure and anchor text into account), represent TF-IDF-like retrieval functions used in document retrieval.

This notebook shows how to use a retriever that uses `ElasticSearch` and `BM25`.

For more information on the details of BM25 see [this blog post](https://www.elastic.co/blog/practical-bm25-part-2-the-bm25-algorithm-and-its-variables).

```
%pip install --upgrade --quiet  elasticsearch
```

```
from langchain_community.retrievers import (    ElasticSearchBM25Retriever,)
```

## Create New Retriever[​](#create-new-retriever "Direct link to Create New Retriever")

```
elasticsearch_url = "http://localhost:9200"retriever = ElasticSearchBM25Retriever.create(elasticsearch_url, "langchain-index-4")
```

```
# Alternatively, you can load an existing index# import elasticsearch# elasticsearch_url="http://localhost:9200"# retriever = ElasticSearchBM25Retriever(elasticsearch.Elasticsearch(elasticsearch_url), "langchain-index")
```

## Add texts (if necessary)[​](#add-texts-if-necessary "Direct link to Add texts (if necessary)")

We can optionally add texts to the retriever (if they aren’t already in there)

```
retriever.add_texts(["foo", "bar", "world", "hello", "foo bar"])
```

```
['cbd4cb47-8d9f-4f34-b80e-ea871bc49856', 'f3bd2e24-76d1-4f9b-826b-ec4c0e8c7365', '8631bfc8-7c12-48ee-ab56-8ad5f373676e', '8be8374c-3253-4d87-928d-d73550a2ecf0', 'd79f457b-2842-4eab-ae10-77aa420b53d7']
```

## Use Retriever[​](#use-retriever "Direct link to Use Retriever")

We can now use the retriever!

```
result = retriever.get_relevant_documents("foo")
```

```
[Document(page_content='foo', metadata={}), Document(page_content='foo bar', metadata={})]
```
## VoyageAI

All functionality related to VoyageAI

> [VoyageAI](https://www.voyageai.com/) Voyage AI builds embedding models, customized for your domain and company, for better retrieval quality.

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

Install the integration package with

```
pip install langchain-voyageai
```

Get a VoyageAI API key and set it as an environment variable (`VOYAGE_API_KEY`)

## Text Embedding Model[​](#text-embedding-model "Direct link to Text Embedding Model")

See a [usage example](https://python.langchain.com/docs/integrations/text_embedding/voyageai/)

```
from langchain_voyageai import VoyageAIEmbeddings
```

## Reranking[​](#reranking "Direct link to Reranking")

See a [usage example](https://python.langchain.com/docs/integrations/document_transformers/voyageai-reranker/)

```
from langchain_voyageai import VoyageAIRerank
```

* * *

#### Help us out by providing feedback on this documentation page:
## WandB Tracing

There are two recommended ways to trace your LangChains:

1.  Setting the `LANGCHAIN_WANDB_TRACING` environment variable to “true”.
2.  Using a context manager with tracing\_enabled() to trace a particular block of code.

**Note** if the environment variable is set, all code will be traced, regardless of whether or not it’s within the context manager.

```
import osos.environ["LANGCHAIN_WANDB_TRACING"] = "true"# wandb documentation to configure wandb using env variables# https://docs.wandb.ai/guides/track/advanced/environment-variables# here we are configuring the wandb project nameos.environ["WANDB_PROJECT"] = "langchain-tracing"from langchain.agents import AgentType, initialize_agent, load_toolsfrom langchain.callbacks import wandb_tracing_enabledfrom langchain_openai import OpenAI
```

```
# Agent run with tracing. Ensure that OPENAI_API_KEY is set appropriately to run this example.llm = OpenAI(temperature=0)tools = load_tools(["llm-math"], llm=llm)
```

```
agent = initialize_agent(    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)agent.run("What is 2 raised to .123243 power?")  # this should be traced# A url with for the trace sesion like the following should print in your console:# https://wandb.ai/<wandb_entity>/<wandb_project>/runs/<run_id># The url can be used to view the trace session in wandb.
```

```
# Now, we unset the environment variable and use a context manager.if "LANGCHAIN_WANDB_TRACING" in os.environ:    del os.environ["LANGCHAIN_WANDB_TRACING"]# enable tracing using a context managerwith wandb_tracing_enabled():    agent.run("What is 5 raised to .123243 power?")  # this should be tracedagent.run("What is 2 raised to .123243 power?")  # this should not be traced
```

```
> Entering new AgentExecutor chain... I need to use a calculator to solve this.Action: CalculatorAction Input: 5^.123243Observation: Answer: 1.2193914912400514Thought: I now know the final answer.Final Answer: 1.2193914912400514> Finished chain.> Entering new AgentExecutor chain... I need to use a calculator to solve this.Action: CalculatorAction Input: 2^.123243Observation: Answer: 1.0891804557407723Thought: I now know the final answer.Final Answer: 1.0891804557407723> Finished chain.
```

* * *

#### Help us out by providing feedback on this documentation page:
## kNN

> In statistics, the [k-nearest neighbours algorithm (k-NN)](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) is a non-parametric supervised learning method first developed by `Evelyn Fix` and `Joseph Hodges` in 1951, and later expanded by `Thomas Cover`. It is used for classification and regression.

This notebook goes over how to use a retriever that under the hood uses a kNN.

Largely based on the code of [Andrej Karpathy](https://github.com/karpathy/randomfun/blob/master/knn_vs_svm.html).

```
from langchain_community.retrievers import KNNRetrieverfrom langchain_openai import OpenAIEmbeddings
```

## Create New Retriever with Texts[​](#create-new-retriever-with-texts "Direct link to Create New Retriever with Texts")

```
retriever = KNNRetriever.from_texts(    ["foo", "bar", "world", "hello", "foo bar"], OpenAIEmbeddings())
```

## Use Retriever[​](#use-retriever "Direct link to Use Retriever")

We can now use the retriever!

```
result = retriever.get_relevant_documents("foo")
```

```
[Document(page_content='foo', metadata={}), Document(page_content='foo bar', metadata={}), Document(page_content='hello', metadata={}), Document(page_content='bar', metadata={})]
```

* * *

#### Help us out by providing feedback on this documentation page:
[WhatsApp](https://www.whatsapp.com/) (also called `WhatsApp Messenger`) is a freeware, cross-platform, centralized instant messaging (IM) and voice-over-IP (VoIP) service. It allows users to send text and voice messages, make voice and video calls, and share images, documents, user locations, and other content.

There isn't any special setup for it.

```
from langchain_community.document_loaders import WhatsAppChatLoader
```
`Weaviate` is a low-latency vector search engine with out-of-the-box support for different media types (text, images, etc.). It offers Semantic Search, Question-Answer Extraction, Classification, Customizable Models (PyTorch/TensorFlow/Keras), etc. Built from scratch in Go, Weaviate stores both objects and vectors, allowing for combining vector search with structured filtering and the fault tolerance of a cloud-native database. It is all accessible through GraphQL, REST, and various client-side programming languages.

```
pip install langchain-weaviate
```

There exists a wrapper around `Weaviate` indexes, allowing you to use it as a vectorstore, whether for semantic search or example selection.
## Metal

> [Metal](https://github.com/getmetal/metal-python) is a managed service for ML Embeddings.

This notebook shows how to use [Metal’s](https://docs.getmetal.io/introduction) retriever.

First, you will need to sign up for Metal and get an API key. You can do so [here](https://docs.getmetal.io/misc-create-app)

```
%pip install --upgrade --quiet  metal_sdk
```

```
from metal_sdk.metal import MetalAPI_KEY = ""CLIENT_ID = ""INDEX_ID = ""metal = Metal(API_KEY, CLIENT_ID, INDEX_ID)
```

## Ingest Documents[​](#ingest-documents "Direct link to Ingest Documents")

You only need to do this if you haven’t already set up an index

```
metal.index({"text": "foo1"})metal.index({"text": "foo"})
```

```
{'data': {'id': '642739aa7559b026b4430e42',  'text': 'foo',  'createdAt': '2023-03-31T19:51:06.748Z'}}
```

## Query[​](#query "Direct link to Query")

Now that our index is set up, we can set up a retriever and start querying it.

```
from langchain_community.retrievers import MetalRetriever
```

```
retriever = MetalRetriever(metal, params={"limit": 2})
```

```
retriever.get_relevant_documents("foo1")
```

```
[Document(page_content='foo1', metadata={'dist': '1.19209289551e-07', 'id': '642739a17559b026b4430e40', 'createdAt': '2023-03-31T19:50:57.853Z'}), Document(page_content='foo1', metadata={'dist': '4.05311584473e-06', 'id': '642738f67559b026b4430e3c', 'createdAt': '2023-03-31T19:48:06.769Z'})]
```
## Wikipedia

> [Wikipedia](https://wikipedia.org/) is a multilingual free online encyclopedia written and maintained by a community of volunteers, known as Wikipedians, through open collaboration and using a wiki-based editing system called MediaWiki. `Wikipedia` is the largest and most-read reference work in history.

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

## Document Loader[​](#document-loader "Direct link to Document Loader")

See a [usage example](https://python.langchain.com/docs/integrations/document_loaders/wikipedia/).

```
from langchain_community.document_loaders import WikipediaLoader
```

## Retriever[​](#retriever "Direct link to Retriever")

See a [usage example](https://python.langchain.com/docs/integrations/retrievers/wikipedia/).

```
from langchain.retrievers import WikipediaRetriever
```

* * *

#### Help us out by providing feedback on this documentation page:
[PubMed®](https://pubmed.ncbi.nlm.nih.gov/) by `The National Center for Biotechnology Information, National Library of Medicine` comprises more than 35 million citations for biomedical literature from `MEDLINE`, life science journals, and online books. Citations may include links to full text content from `PubMed Central` and publisher web sites.

```
[Document(page_content='', metadata={'uid': '37549050', 'Title': 'ChatGPT: "To Be or Not to Be" in Bikini Bottom.', 'Published': '--', 'Copyright Information': ''}), Document(page_content="BACKGROUND: ChatGPT is a large language model that has performed well on professional examinations in the fields of medicine, law, and business. However, it is unclear how ChatGPT would perform on an examination assessing professionalism and situational judgement for doctors.\nOBJECTIVE: We evaluated the performance of ChatGPT on the Situational Judgement Test (SJT): a national examination taken by all final-year medical students in the United Kingdom. This examination is designed to assess attributes such as communication, teamwork, patient safety, prioritization skills, professionalism, and ethics.\nMETHODS: All questions from the UK Foundation Programme Office's (UKFPO's) 2023 SJT practice examination were inputted into ChatGPT. For each question, ChatGPT's answers and rationales were recorded and assessed on the basis of the official UK Foundation Programme Office scoring template. Questions were categorized into domains of Good Medical Practice on the basis of the domains referenced in the rationales provided in the scoring sheet. Questions without clear domain links were screened by reviewers and assigned one or multiple domains. ChatGPT's overall performance, as well as its performance across the domains of Good Medical Practice, was evaluated.\nRESULTS: Overall, ChatGPT performed well, scoring 76% on the SJT but scoring full marks on only a few questions (9%), which may reflect possible flaws in ChatGPT's situational judgement or inconsistencies in the reasoning across questions (or both) in the examination itself. ChatGPT demonstrated consistent performance across the 4 outlined domains in Good Medical Practice for doctors.\nCONCLUSIONS: Further research is needed to understand the potential applications of large language models, such as ChatGPT, in medical education for standardizing questions and providing consistent rationales for examinations assessing professionalism and ethics.", metadata={'uid': '37548997', 'Title': 'Performance of ChatGPT on the Situational Judgement Test-A Professional Dilemmas-Based Examination for Doctors in the United Kingdom.', 'Published': '2023-08-07', 'Copyright Information': '©Robin J Borchert, Charlotte R Hickman, Jack Pepys, Timothy J Sadler. Originally published in JMIR Medical Education (https://mededu.jmir.org), 07.08.2023.'}), Document(page_content='', metadata={'uid': '37548971', 'Title': "Large Language Models Answer Medical Questions Accurately, but Can't Match Clinicians' Knowledge.", 'Published': '2023-08-07', 'Copyright Information': ''})]
```
## Xorbits Inference (Xinference)

This page demonstrates how to use [Xinference](https://github.com/xorbitsai/inference) with LangChain.

`Xinference` is a powerful and versatile library designed to serve LLMs, speech recognition models, and multimodal models, even on your laptop. With Xorbits Inference, you can effortlessly deploy and serve your or state-of-the-art built-in models using just a single command.

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

Xinference can be installed via pip from PyPI:

```
pip install "xinference[all]"
```

## LLM[​](#llm "Direct link to LLM")

Xinference supports various models compatible with GGML, including chatglm, baichuan, whisper, vicuna, and orca. To view the builtin models, run the command:

### Wrapper for Xinference[​](#wrapper-for-xinference "Direct link to Wrapper for Xinference")

You can start a local instance of Xinference by running:

You can also deploy Xinference in a distributed cluster. To do so, first start an Xinference supervisor on the server you want to run it:

```
xinference-supervisor -H "${supervisor_host}"
```

Then, start the Xinference workers on each of the other servers where you want to run them on:

```
xinference-worker -e "http://${supervisor_host}:9997"
```

You can also start a local instance of Xinference by running:

Once Xinference is running, an endpoint will be accessible for model management via CLI or Xinference client.

For local deployment, the endpoint will be http://localhost:9997.

For cluster deployment, the endpoint will be http://${supervisor\_host}:9997.

Then, you need to launch a model. You can specify the model names and other attributes including model\_size\_in\_billions and quantization. You can use command line interface (CLI) to do it. For example,

```
xinference launch -n orca -s 3 -q q4_0
```

A model uid will be returned.

Example usage:

```
from langchain_community.llms import Xinferencellm = Xinference(    server_url="http://0.0.0.0:9997",    model_uid = {model_uid} # replace model_uid with the model UID return from launching the model)llm(    prompt="Q: where can we visit in the capital of France? A:",    generate_config={"max_tokens": 1024, "stream": True},)
```

### Usage[​](#usage "Direct link to Usage")

For more information and detailed examples, refer to the [example for xinference LLMs](https://python.langchain.com/docs/integrations/llms/xinference/)

### Embeddings[​](#embeddings "Direct link to Embeddings")

Xinference also supports embedding queries and documents. See [example for xinference embeddings](https://python.langchain.com/docs/integrations/text_embedding/xinference/) for a more detailed demo.
## Yandex

All functionality related to Yandex Cloud

> [Yandex Cloud](https://cloud.yandex.com/en/) is a public cloud platform.

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

Yandex Cloud SDK can be installed via pip from PyPI:

## LLMs[​](#llms "Direct link to LLMs")

### YandexGPT[​](#yandexgpt "Direct link to YandexGPT")

See a [usage example](https://python.langchain.com/docs/integrations/llms/yandex/).

```
from langchain_community.llms import YandexGPT
```

## Chat models[​](#chat-models "Direct link to Chat models")

### YandexGPT[​](#yandexgpt-1 "Direct link to YandexGPT")

See a [usage example](https://python.langchain.com/docs/integrations/chat/yandex/).

```
from langchain_community.chat_models import ChatYandexGPT
```

* * *

#### Help us out by providing feedback on this documentation page:
[Xata](https://xata.io/) is a serverless data platform, based on `PostgreSQL`. It provides a Python SDK for interacting with your database, and a UI for managing your data. `Xata` has a native vector type, which can be added to any table, and supports similarity search. LangChain inserts vectors directly to `Xata`, and queries it for the nearest neighbors of a given vector, so that you can use all the LangChain Embeddings integrations with `Xata`.

We need to install `xata` python package.

```
pip install xata==1.0.0a7 
```
## Yeager.ai

This page covers how to use [Yeager.ai](https://yeager.ai/) to generate LangChain tools and agents.

## What is Yeager.ai?[​](#what-is-yeagerai "Direct link to What is Yeager.ai?")

Yeager.ai is an ecosystem designed to simplify the process of creating AI agents and tools.

It features yAgents, a No-code LangChain Agent Builder, which enables users to build, test, and deploy AI solutions with ease. Leveraging the LangChain framework, yAgents allows seamless integration with various language models and resources, making it suitable for developers, researchers, and AI enthusiasts across diverse applications.

## yAgents[​](#yagents "Direct link to yAgents")

Low code generative agent designed to help you build, prototype, and deploy Langchain tools with ease.

### How to use?[​](#how-to-use "Direct link to How to use?")

```
pip install yeagerai-agentyeagerai-agent
```

Go to [http://127.0.0.1:7860](http://127.0.0.1:7860/)

This will install the necessary dependencies and set up yAgents on your system. After the first run, yAgents will create a .env file where you can input your OpenAI API key. You can do the same directly from the Gradio interface under the tab "Settings".

`OPENAI_API_KEY=<your_openai_api_key_here>`

We recommend using GPT-4,. However, the tool can also work with GPT-3 if the problem is broken down sufficiently.

### Creating and Executing Tools with yAgents[​](#creating-and-executing-tools-with-yagents "Direct link to Creating and Executing Tools with yAgents")

yAgents makes it easy to create and execute AI-powered tools. Here's a brief overview of the process:

1.  Create a tool: To create a tool, provide a natural language prompt to yAgents. The prompt should clearly describe the tool's purpose and functionality. For example: `create a tool that returns the n-th prime number`
    
2.  Load the tool into the toolkit: To load a tool into yAgents, simply provide a command to yAgents that says so. For example: `load the tool that you just created it into your toolkit`
    
3.  Execute the tool: To run a tool or agent, simply provide a command to yAgents that includes the name of the tool and any required parameters. For example: `generate the 50th prime number`
    

You can see a video of how it works [here](https://www.youtube.com/watch?v=KA5hCM3RaWE).

As you become more familiar with yAgents, you can create more advanced tools and agents to automate your work and enhance your productivity.

For more information, see [yAgents' Github](https://github.com/yeagerai/yeagerai-agent) or our [docs](https://yeagerai.gitbook.io/docs/general/welcome-to-yeager.ai)
This notebook demonstrates how to use the `ArceeRetriever` class to retrieve relevant document(s) for Arcee’s `Domain Adapted Language Models` (`DALMs`).

Before using `ArceeRetriever`, make sure the Arcee API key is set as `ARCEE_API_KEY` environment variable. You can also pass the api key as a named parameter.

You can also configure `ArceeRetriever`’s parameters such as `arcee_api_url`, `arcee_app_url`, and `model_kwargs` as needed. Setting the `model_kwargs` at the object initialization uses the filters and size as default for all the subsequent retrievals.

```
retriever = ArceeRetriever(    model="DALM-PubMed",    # arcee_api_key="ARCEE-API-KEY", # if not already set in the environment    arcee_api_url="https://custom-api.arcee.ai",  # default is https://api.arcee.ai    arcee_app_url="https://custom-app.arcee.ai",  # default is https://app.arcee.ai    model_kwargs={        "size": 5,        "filters": [            {                "field_name": "document",                "filter_type": "fuzzy_search",                "value": "Einstein",            }        ],    },)
```

You can retrieve relevant documents from uploaded contexts by providing a query. Here’s an example:

Arcee allows you to apply `filters` and set the `size` (in terms of count) of retrieved document(s). Filters help narrow down the results. Here’s how to use these parameters:

```
# Define filtersfilters = [    {"field_name": "document", "filter_type": "fuzzy_search", "value": "Music"},    {"field_name": "year", "filter_type": "strict_search", "value": "1905"},]# Retrieve documents with filters and size paramsdocuments = retriever.get_relevant_documents(query=query, size=5, filters=filters)
```
## Amazon Kendra

> [Amazon Kendra](https://docs.aws.amazon.com/kendra/latest/dg/what-is-kendra.html) is an intelligent search service provided by `Amazon Web Services` (`AWS`). It utilizes advanced natural language processing (NLP) and machine learning algorithms to enable powerful search capabilities across various data sources within an organization. `Kendra` is designed to help users find the information they need quickly and accurately, improving productivity and decision-making.

> With `Kendra`, users can search across a wide range of content types, including documents, FAQs, knowledge bases, manuals, and websites. It supports multiple languages and can understand complex queries, synonyms, and contextual meanings to provide highly relevant search results.

## Using the Amazon Kendra Index Retriever[​](#using-the-amazon-kendra-index-retriever "Direct link to Using the Amazon Kendra Index Retriever")

```
%pip install --upgrade --quiet  boto3
```

```
from langchain_community.retrievers import AmazonKendraRetriever
```

Create New Retriever

```
retriever = AmazonKendraRetriever(index_id="c0806df7-e76b-4bce-9b5c-d5582f6b1a03")
```

Now you can use retrieved documents from Kendra index

```
retriever.get_relevant_documents("what is langchain")
```

* * *

#### Help us out by providing feedback on this documentation page:
## Bedrock (Knowledge Bases)

> [Knowledge bases for Amazon Bedrock](https://aws.amazon.com/bedrock/knowledge-bases/) is an Amazon Web Services (AWS) offering which lets you quickly build RAG applications by using your private data to customize FM response.

> Implementing `RAG` requires organizations to perform several cumbersome steps to convert data into embeddings (vectors), store the embeddings in a specialized vector database, and build custom integrations into the database to search and retrieve text relevant to the user’s query. This can be time-consuming and inefficient.

> With `Knowledge Bases for Amazon Bedrock`, simply point to the location of your data in `Amazon S3`, and `Knowledge Bases for Amazon Bedrock` takes care of the entire ingestion workflow into your vector database. If you do not have an existing vector database, Amazon Bedrock creates an Amazon OpenSearch Serverless vector store for you. For retrievals, use the Langchain - Amazon Bedrock integration via the Retrieve API to retrieve relevant results for a user query from knowledge bases.

> Knowledge base can be configured through [AWS Console](https://aws.amazon.com/console/) or by using [AWS SDKs](https://aws.amazon.com/developer/tools/).

## Using the Knowledge Bases Retriever[​](#using-the-knowledge-bases-retriever "Direct link to Using the Knowledge Bases Retriever")

```
%pip install --upgrade --quiet  boto3
```

```
from langchain_community.retrievers import AmazonKnowledgeBasesRetrieverretriever = AmazonKnowledgeBasesRetriever(    knowledge_base_id="PUIJP4EQUA",    retrieval_config={"vectorSearchConfiguration": {"numberOfResults": 4}},)
```

```
query = "What did the president say about Ketanji Brown?"retriever.get_relevant_documents(query=query)
```

### Using in a QA Chain[​](#using-in-a-qa-chain "Direct link to Using in a QA Chain")

```
from botocore.client import Configfrom langchain.chains import RetrievalQAfrom langchain_community.llms import Bedrockmodel_kwargs_claude = {"temperature": 0, "top_k": 10, "max_tokens_to_sample": 3000}llm = Bedrock(model_id="anthropic.claude-v2", model_kwargs=model_kwargs_claude)qa = RetrievalQA.from_chain_type(    llm=llm, retriever=retriever, return_source_documents=True)qa(query)
```

* * *

#### Help us out by providing feedback on this documentation page:
## TF-IDF

> [TF-IDF](https://scikit-learn.org/stable/modules/feature_extraction.html#tfidf-term-weighting) means term-frequency times inverse document-frequency.

This notebook goes over how to use a retriever that under the hood uses [TF-IDF](https://en.wikipedia.org/wiki/Tf%E2%80%93idf) using `scikit-learn` package.

For more information on the details of TF-IDF see [this blog post](https://medium.com/data-science-bootcamp/tf-idf-basics-of-information-retrieval-48de122b2a4c).

```
%pip install --upgrade --quiet  scikit-learn
```

```
from langchain_community.retrievers import TFIDFRetriever
```

## Create New Retriever with Texts[​](#create-new-retriever-with-texts "Direct link to Create New Retriever with Texts")

```
retriever = TFIDFRetriever.from_texts(["foo", "bar", "world", "hello", "foo bar"])
```

## Create a New Retriever with Documents[​](#create-a-new-retriever-with-documents "Direct link to Create a New Retriever with Documents")

You can now create a new retriever with the documents you created.

```
from langchain_core.documents import Documentretriever = TFIDFRetriever.from_documents(    [        Document(page_content="foo"),        Document(page_content="bar"),        Document(page_content="world"),        Document(page_content="hello"),        Document(page_content="foo bar"),    ])
```

## Use Retriever[​](#use-retriever "Direct link to Use Retriever")

We can now use the retriever!

```
result = retriever.get_relevant_documents("foo")
```

```
[Document(page_content='foo', metadata={}), Document(page_content='foo bar', metadata={}), Document(page_content='hello', metadata={}), Document(page_content='world', metadata={})]
```

## Save and load[​](#save-and-load "Direct link to Save and load")

You can easily save and load this retriever, making it handy for local development!

```
retriever.save_local("testing.pkl")
```

```
retriever_copy = TFIDFRetriever.load_local("testing.pkl")
```

```
retriever_copy.get_relevant_documents("foo")
```

```
[Document(page_content='foo', metadata={}), Document(page_content='foo bar', metadata={}), Document(page_content='hello', metadata={}), Document(page_content='world', metadata={})]
```
## Vespa

> [Vespa](https://vespa.ai/) is a fully featured search engine and vector database. It supports vector search (ANN), lexical search, and search in structured data, all in the same query.

This notebook shows how to use `Vespa.ai` as a LangChain retriever.

In order to create a retriever, we use [pyvespa](https://pyvespa.readthedocs.io/en/latest/index.html) to create a connection a `Vespa` service.

```
%pip install --upgrade --quiet  pyvespa
```

```
from vespa.application import Vespavespa_app = Vespa(url="https://doc-search.vespa.oath.cloud")
```

This creates a connection to a `Vespa` service, here the Vespa documentation search service. Using `pyvespa` package, you can also connect to a [Vespa Cloud instance](https://pyvespa.readthedocs.io/en/latest/deploy-vespa-cloud.html) or a local [Docker instance](https://pyvespa.readthedocs.io/en/latest/deploy-docker.html).

After connecting to the service, you can set up the retriever:

```
from langchain_community.retrievers import VespaRetrievervespa_query_body = {    "yql": "select content from paragraph where userQuery()",    "hits": 5,    "ranking": "documentation",    "locale": "en-us",}vespa_content_field = "content"retriever = VespaRetriever(vespa_app, vespa_query_body, vespa_content_field)
```

This sets up a LangChain retriever that fetches documents from the Vespa application. Here, up to 5 results are retrieved from the `content` field in the `paragraph` document type, using `doumentation` as the ranking method. The `userQuery()` is replaced with the actual query passed from LangChain.

Please refer to the [pyvespa documentation](https://pyvespa.readthedocs.io/en/latest/getting-started-pyvespa.html#Query) for more information.

Now you can return the results and continue using the results in LangChain.

```
retriever.get_relevant_documents("what is vespa?")
```
## SVM

> [Support vector machines (SVMs)](https://scikit-learn.org/stable/modules/svm.html#support-vector-machines) are a set of supervised learning methods used for classification, regression and outliers detection.

This notebook goes over how to use a retriever that under the hood uses an `SVM` using `scikit-learn` package.

Largely based on [https://github.com/karpathy/randomfun/blob/master/knn\_vs\_svm.html](https://github.com/karpathy/randomfun/blob/master/knn_vs_svm.html)

```
%pip install --upgrade --quiet  scikit-learn
```

```
%pip install --upgrade --quiet  lark
```

We want to use `OpenAIEmbeddings` so we have to get the OpenAI API Key.

```
import getpassimport osos.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API Key:")
```

```
from langchain_community.retrievers import SVMRetrieverfrom langchain_openai import OpenAIEmbeddings
```

## Create New Retriever with Texts[​](#create-new-retriever-with-texts "Direct link to Create New Retriever with Texts")

```
retriever = SVMRetriever.from_texts(    ["foo", "bar", "world", "hello", "foo bar"], OpenAIEmbeddings())
```

## Use Retriever[​](#use-retriever "Direct link to Use Retriever")

We can now use the retriever!

```
result = retriever.get_relevant_documents("foo")
```

```
[Document(page_content='foo', metadata={}), Document(page_content='foo bar', metadata={}), Document(page_content='hello', metadata={}), Document(page_content='world', metadata={})]
```
This notebook shows how to use a retriever that uses `SingleStoreDB`.

```
import getpassimport os# We want to use OpenAIEmbeddings so we have to get the OpenAI API Key.os.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API Key:")from langchain_community.document_loaders import TextLoaderfrom langchain_community.vectorstores import SingleStoreDBfrom langchain_openai import OpenAIEmbeddingsfrom langchain_text_splitters import CharacterTextSplitterloader = TextLoader("../../modules/state_of_the_union.txt")documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)docs = text_splitter.split_documents(documents)embeddings = OpenAIEmbeddings()# Setup connection url as environment variableos.environ["SINGLESTOREDB_URL"] = "root:pass@localhost:3306/db"# Load documents to the storedocsearch = SingleStoreDB.from_documents(    docs,    embeddings,    table_name="notebook",  # use table with a custom name)# create retriever from the vector storeretriever = docsearch.as_retriever(search_kwargs={"k": 2})
```
## Stores

In many different applications, having some sort of key-value storage is helpful. In this section, we will look at a few different ways to store key-value pairs using implementations of the `ByteStore` interface.

## Features (natively supported)[​](#features-natively-supported "Direct link to Features (natively supported)")

All `ByteStore`s support the following functions, which are used for modifying **m**ultiple key-value pairs at once:

*   `mget(key: Sequence[str]) -> List[Optional[bytes]]`: get the contents of multiple keys, returning `None` if the key does not exist
*   `mset(key_value_pairs: Sequence[Tuple[str, bytes]]) -> None`: set the contents of multiple keys
*   `mdelete(key: Sequence[str]) -> None`: delete multiple keys
*   `yield_keys(prefix: Optional[str] = None) -> Iterator[str]`: yield all keys in the store, optionally filtering by a prefix

## How to pick one[​](#how-to-pick-one "Direct link to How to pick one")

`ByteStore`s are designed to be interchangeable. By default, most dependent integrations use the `InMemoryByteStore`, which is a simple in-memory key-value store.

However, if you start having other requirements, like massive scalability or persistence, you can swap out the `ByteStore` implementation with one of the other ones documented in this section.
The `UpstashRedisStore` is an implementation of `ByteStore` that stores everything in your Upstash-hosted Redis instance.

```
from langchain.storage import UpstashRedisByteStorefrom upstash_redis import RedisURL = "<UPSTASH_REDIS_REST_URL>"TOKEN = "<UPSTASH_REDIS_REST_TOKEN>"redis_client = Redis(url=URL, token=TOKEN)store = UpstashRedisByteStore(client=redis_client, ttl=None, namespace="test-ns")store.mset([("k1", b"v1"), ("k2", b"v2")])print(store.mget(["k1", "k2"]))
```