Connect to an existing Redis index.
Parameters
embedding (langchain.embeddings.base.Embeddings) –
index_name (str) –
content_key (str) –
metadata_key (str) –
vector_key (str) –
kwargs (Any) –
Return type
langchain.vectorstores.redis.Redis
as_retriever(**kwargs)[source]
Parameters
kwargs (Any) –
Return type
langchain.vectorstores.redis.RedisVectorStoreRetriever
class langchain.vectorstores.Rockset(client, embeddings, collection_name, text_key, embedding_key)[source]
Bases: langchain.vectorstores.base.VectorStore
Wrapper arpund Rockset vector database.
To use, you should have the rockset python package installed. Note that to use
this, the collection being used must already exist in your Rockset instance.
You must also ensure you use a Rockset ingest transformation to apply
VECTOR_ENFORCE on the column being used to store embedding_key in the
collection.
See: https://rockset.com/blog/introducing-vector-search-on-rockset/ for more details
Everything below assumes commons Rockset workspace.
TODO: Add support for workspace args.
Example
from langchain.vectorstores import Rockset
from langchain.embeddings.openai import OpenAIEmbeddings
import rockset
# Make sure you use the right host (region) for your Rockset instance
# and APIKEY has both read-write access to your collection.
rs = rockset.RocksetClient(host=rockset.Regions.use1a1, api_key="***")
collection_name = "langchain_demo"
embeddings = OpenAIEmbeddings()
vectorstore = Rockset(rs, collection_name, embeddings,
    "description", "description_embedding")
Parameters
client (Any) –
embeddings (Embeddings) –


Parameters
client (Any) –
embeddings (Embeddings) –
collection_name (str) –
text_key (str) –
embedding_key (str) –
add_texts(texts, metadatas=None, ids=None, batch_size=32, **kwargs)[source]
Run more texts through the embeddings and add to the vectorstore
Args:
texts: Iterable of strings to add to the vectorstore.
metadatas: Optional list of metadatas associated with the texts.
ids: Optional list of ids to associate with the texts.
batch_size: Send documents in batches to rockset.
Returns
List of ids from adding the texts into the vectorstore.
Parameters
texts (Iterable[str]) –
metadatas (Optional[List[dict]]) –
ids (Optional[List[str]]) –
batch_size (int) –
kwargs (Any) –
Return type
List[str]
classmethod from_texts(texts, embedding, metadatas=None, client=None, collection_name='', text_key='', embedding_key='', ids=None, batch_size=32, **kwargs)[source]
Create Rockset wrapper with existing texts.
This is intended as a quicker way to get started.
Parameters
texts (List[str]) –
embedding (langchain.embeddings.base.Embeddings) –
metadatas (Optional[List[dict]]) –
client (Any) –
collection_name (str) –
text_key (str) –
embedding_key (str) –
ids (Optional[List[str]]) –
batch_size (int) –
kwargs (Any) –
Return type
langchain.vectorstores.rocksetdb.Rockset


Return type
langchain.vectorstores.rocksetdb.Rockset
class DistanceFunction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases: enum.Enum
COSINE_SIM = 'COSINE_SIM'
EUCLIDEAN_DIST = 'EUCLIDEAN_DIST'
DOT_PRODUCT = 'DOT_PRODUCT'
order_by()[source]
Return type
str
similarity_search_with_relevance_scores(query, k=4, distance_func=DistanceFunction.COSINE_SIM, where_str=None, **kwargs)[source]
Perform a similarity search with Rockset
Parameters
query (str) – Text to look up documents similar to.
distance_func (DistanceFunction) – how to compute distance between two
vectors in Rockset.
k (int, optional) – Top K neighbors to retrieve. Defaults to 4.
where_str (Optional[str], optional) – Metadata filters supplied as a
SQL where condition string. Defaults to None.
eg. “price<=70.0 AND brand=’Nintendo’”
NOTE – Please do not let end-user to fill this and always be aware
of SQL injection.
kwargs (Any) –
Returns
List of documents with their relevance score
Return type
List[Tuple[Document, float]]
similarity_search(query, k=4, distance_func=DistanceFunction.COSINE_SIM, where_str=None, **kwargs)[source]
Same as similarity_search_with_relevance_scores but
doesn’t return the scores.
Parameters
query (str) –
k (int) –
distance_func (DistanceFunction) –
where_str (Optional[str]) –
kwargs (Any) –
Return type
List[Document]


kwargs (Any) –
Return type
List[Document]
similarity_search_by_vector(embedding, k=4, distance_func=DistanceFunction.COSINE_SIM, where_str=None, **kwargs)[source]
Accepts a query_embedding (vector), and returns documents with
similar embeddings.
Parameters
embedding (List[float]) –
k (int) –
distance_func (DistanceFunction) –
where_str (Optional[str]) –
kwargs (Any) –
Return type
List[Document]
similarity_search_by_vector_with_relevance_scores(embedding, k=4, distance_func=DistanceFunction.COSINE_SIM, where_str=None, **kwargs)[source]
Accepts a query_embedding (vector), and returns documents with
similar embeddings along with their relevance scores.
Parameters
embedding (List[float]) –
k (int) –
distance_func (DistanceFunction) –
where_str (Optional[str]) –
kwargs (Any) –
Return type
List[Tuple[Document, float]]
delete_texts(ids)[source]
Delete a list of docs from the Rockset collection
Parameters
ids (List[str]) –
Return type
None
class langchain.vectorstores.SKLearnVectorStore(embedding, *, persist_path=None, serializer='json', metric='cosine', **kwargs)[source]
Bases: langchain.vectorstores.base.VectorStore
A simple in-memory vector store based on the scikit-learn library
NearestNeighbors implementation.
Parameters
embedding (langchain.embeddings.base.Embeddings) –
persist_path (Optional[str]) –
serializer (Literal['json', 'bson', 'parquet']) –
metric (str) –
kwargs (Any) –
Return type
None
persist()[source]
Return type


Return type
None
persist()[source]
Return type
None
add_texts(texts, metadatas=None, ids=None, **kwargs)[source]
Run more texts through the embeddings and add to the vectorstore.
Parameters
texts (Iterable[str]) – Iterable of strings to add to the vectorstore.
metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts.
kwargs (Any) – vectorstore specific parameters
ids (Optional[List[str]]) –
Returns
List of ids from adding the texts into the vectorstore.
Return type
List[str]
similarity_search_with_score(query, *, k=4, **kwargs)[source]
Parameters
query (str) –
k (int) –
kwargs (Any) –
Return type
List[Tuple[langchain.schema.Document, float]]
similarity_search(query, k=4, **kwargs)[source]
Return docs most similar to query.
Parameters
query (str) –
k (int) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
max_marginal_relevance_search_by_vector(embedding, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
:param embedding: Embedding to look up documents similar to.
:param k: Number of Documents to return. Defaults to 4.
:param fetch_k: Number of Documents to fetch to pass to MMR algorithm.
:param lambda_mult: Number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to maximum diversity and 1 to minimum diversity.


to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
Returns
List of Documents selected by maximal marginal relevance.
Parameters
embedding (List[float]) –
k (int) –
fetch_k (int) –
lambda_mult (float) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
max_marginal_relevance_search(query, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
:param query: Text to look up documents similar to.
:param k: Number of Documents to return. Defaults to 4.
:param fetch_k: Number of Documents to fetch to pass to MMR algorithm.
:param lambda_mult: Number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
Returns
List of Documents selected by maximal marginal relevance.
Parameters
query (str) –
k (int) –
fetch_k (int) –
lambda_mult (float) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
classmethod from_texts(texts, embedding, metadatas=None, ids=None, persist_path=None, **kwargs)[source]
Return VectorStore initialized from texts and embeddings.
Parameters
texts (List[str]) –
embedding (langchain.embeddings.base.Embeddings) –
metadatas (Optional[List[dict]]) –
ids (Optional[List[str]]) –
persist_path (Optional[str]) –
kwargs (Any) –
Return type


persist_path (Optional[str]) –
kwargs (Any) –
Return type
langchain.vectorstores.sklearn.SKLearnVectorStore
class langchain.vectorstores.StarRocks(embedding, config=None, **kwargs)[source]
Bases: langchain.vectorstores.base.VectorStore
Wrapper around StarRocks vector database
You need a pymysql python package, and a valid account
to connect to StarRocks.
Right now StarRocks has only implemented cosine_similarity function to
compute distance between two vectors. And there is no vector inside right now,
so we have to iterate all vectors and compute spatial distance.
For more information, please visit[StarRocks official site](https://www.starrocks.io/)
[StarRocks github](https://github.com/StarRocks/starrocks)
Parameters
embedding (Embeddings) –
config (Optional[StarRocksSettings]) –
kwargs (Any) –
Return type
None
escape_str(value)[source]
Parameters
value (str) –
Return type
str
add_texts(texts, metadatas=None, batch_size=32, ids=None, **kwargs)[source]
Insert more texts through the embeddings and add to the VectorStore.
Parameters
texts (Iterable[str]) – Iterable of strings to add to the VectorStore.
ids (Optional[Iterable[str]]) – Optional list of ids to associate with the texts.
batch_size (int) – Batch size of insertion
metadata – Optional column data to be inserted
metadatas (Optional[List[dict]]) –
kwargs (Any) –
Returns
List of ids from adding the texts into the VectorStore.
Return type
List[str]


List of ids from adding the texts into the VectorStore.
Return type
List[str]
classmethod from_texts(texts, embedding, metadatas=None, config=None, text_ids=None, batch_size=32, **kwargs)[source]
Create StarRocks wrapper with existing texts
Parameters
embedding_function (Embeddings) – Function to extract text embedding
texts (Iterable[str]) – List or tuple of strings to be added
config (StarRocksSettings, Optional) – StarRocks configuration
text_ids (Optional[Iterable], optional) – IDs for the texts.
Defaults to None.
batch_size (int, optional) – Batchsize when transmitting data to StarRocks.
Defaults to 32.
metadata (List[dict], optional) – metadata to texts. Defaults to None.
embedding (langchain.embeddings.base.Embeddings) –
metadatas (Optional[List[Dict[Any, Any]]]) –
kwargs (Any) –
Returns
StarRocks Index
Return type
langchain.vectorstores.starrocks.StarRocks
similarity_search(query, k=4, where_str=None, **kwargs)[source]
Perform a similarity search with StarRocks
Parameters
query (str) – query string
k (int, optional) – Top K neighbors to retrieve. Defaults to 4.
where_str (Optional[str], optional) – where condition string.
Defaults to None.
NOTE – Please do not let end-user to fill this and always be aware
of SQL injection. When dealing with metadatas, remember to
use {self.metadata_column}.attribute instead of attribute
alone. The default name for it is metadata.
kwargs (Any) –
Returns
List of Documents
Return type
List[Document]


Returns
List of Documents
Return type
List[Document]
similarity_search_by_vector(embedding, k=4, where_str=None, **kwargs)[source]
Perform a similarity search with StarRocks by vectors
Parameters
query (str) – query string
k (int, optional) – Top K neighbors to retrieve. Defaults to 4.
where_str (Optional[str], optional) – where condition string.
Defaults to None.
NOTE – Please do not let end-user to fill this and always be aware
of SQL injection. When dealing with metadatas, remember to
use {self.metadata_column}.attribute instead of attribute
alone. The default name for it is metadata.
embedding (List[float]) –
kwargs (Any) –
Returns
List of (Document, similarity)
Return type
List[Document]
similarity_search_with_relevance_scores(query, k=4, where_str=None, **kwargs)[source]
Perform a similarity search with StarRocks
Parameters
query (str) – query string
k (int, optional) – Top K neighbors to retrieve. Defaults to 4.
where_str (Optional[str], optional) – where condition string.
Defaults to None.
NOTE – Please do not let end-user to fill this and always be aware
of SQL injection. When dealing with metadatas, remember to
use {self.metadata_column}.attribute instead of attribute
alone. The default name for it is metadata.
kwargs (Any) –
Returns
List of documents
Return type
List[Document]
drop()[source]
Helper function: Drop data
Return type
None
property metadata_column: str
class langchain.vectorstores.SupabaseVectorStore(client, embedding, table_name, query_name=None)[source]
Bases: langchain.vectorstores.base.VectorStore


Bases: langchain.vectorstores.base.VectorStore
VectorStore for a Supabase postgres database. Assumes you have the pgvector
extension installed and a match_documents (or similar) function. For more details:
https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase
You can implement your own match_documents function in order to limit the search
space to a subset of documents based on your own authorization or business logic.
Note that the Supabase Python client does not yet support async operations.
If you’d like to use max_marginal_relevance_search, please review the instructions
below on modifying the match_documents function to return matched embeddings.
Parameters
client (supabase.client.Client) –
embedding (Embeddings) –
table_name (str) –
query_name (Union[str, None]) –
Return type
None
table_name: str
query_name: str
add_texts(texts, metadatas=None, ids=None, **kwargs)[source]
Run more texts through the embeddings and add to the vectorstore.
Parameters
texts (Iterable[str]) – Iterable of strings to add to the vectorstore.
metadatas (Optional[List[dict[Any, Any]]]) – Optional list of metadatas associated with the texts.
kwargs (Any) – vectorstore specific parameters
ids (Optional[List[str]]) –
Returns
List of ids from adding the texts into the vectorstore.
Return type
List[str]
classmethod from_texts(texts, embedding, metadatas=None, client=None, table_name='documents', query_name='match_documents', ids=None, **kwargs)[source]
Return VectorStore initialized from texts and embeddings.
Parameters
texts (List[str]) –
embedding (Embeddings) –


Parameters
texts (List[str]) –
embedding (Embeddings) –
metadatas (Optional[List[dict]]) –
client (Optional[supabase.client.Client]) –
table_name (Optional[str]) –
query_name (Union[str, None]) –
ids (Optional[List[str]]) –
kwargs (Any) –
Return type
SupabaseVectorStore
add_vectors(vectors, documents, ids)[source]
Parameters
vectors (List[List[float]]) –
documents (List[langchain.schema.Document]) –
ids (List[str]) –
Return type
List[str]
similarity_search(query, k=4, **kwargs)[source]
Return docs most similar to query.
Parameters
query (str) –
k (int) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
similarity_search_by_vector(embedding, k=4, **kwargs)[source]
Return docs most similar to embedding vector.
Parameters
embedding (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
kwargs (Any) –
Returns
List of Documents most similar to the query vector.
Return type
List[langchain.schema.Document]
similarity_search_with_relevance_scores(query, k=4, **kwargs)[source]
Return docs and relevance scores in the range [0, 1].
0 is dissimilar, 1 is most similar.
Parameters
query (str) – input text
k (int) – Number of Documents to return. Defaults to 4.
**kwargs – kwargs to be passed to similarity search. Should include:


**kwargs – kwargs to be passed to similarity search. Should include:
score_threshold: Optional, a floating point value between 0 to 1 to
filter the resulting set of retrieved docs
kwargs (Any) –
Returns
List of Tuples of (doc, similarity_score)
Return type
List[Tuple[langchain.schema.Document, float]]
similarity_search_by_vector_with_relevance_scores(query, k)[source]
Parameters
query (List[float]) –
k (int) –
Return type
List[Tuple[langchain.schema.Document, float]]
similarity_search_by_vector_returning_embeddings(query, k)[source]
Parameters
query (List[float]) –
k (int) –
Return type
List[Tuple[langchain.schema.Document, float, numpy.ndarray[numpy.float32, Any]]]
max_marginal_relevance_search_by_vector(embedding, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
embedding (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – Number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
kwargs (Any) –
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[langchain.schema.Document]


Return type
List[langchain.schema.Document]
max_marginal_relevance_search(query, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – Number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
kwargs (Any) –
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[langchain.schema.Document]
max_marginal_relevance_search requires that query_name returns matched
embeddings alongside the match documents. The following function
demonstrates how to do this:
```sql
CREATE FUNCTION match_documents_embeddings(query_embedding vector(1536),
match_count int)
RETURNS TABLE(id bigint,
content text,
metadata jsonb,
embedding vector(1536),
similarity float)
LANGUAGE plpgsql
AS $$
# variable_conflict use_column
BEGINRETURN query
SELECT
id,
content,
metadata,
embedding,
1 -(docstore.embedding <=> query_embedding) AS similarity
FROMdocstore
ORDER BYdocstore.embedding <=> query_embedding
LIMIT match_count;
END;
$$;
```
delete(ids)[source]
Delete by vector IDs.
Parameters
ids (List[str]) – List of ids to delete.
Return type
None


Parameters
ids (List[str]) – List of ids to delete.
Return type
None
class langchain.vectorstores.Tair(embedding_function, url, index_name, content_key='content', metadata_key='metadata', search_params=None, **kwargs)[source]
Bases: langchain.vectorstores.base.VectorStore
Wrapper around Tair Vector store.
Parameters
embedding_function (Embeddings) –
url (str) –
index_name (str) –
content_key (str) –
metadata_key (str) –
search_params (Optional[dict]) –
kwargs (Any) –
create_index_if_not_exist(dim, distance_type, index_type, data_type, **kwargs)[source]
Parameters
dim (int) –
distance_type (str) –
index_type (str) –
data_type (str) –
kwargs (Any) –
Return type
bool
add_texts(texts, metadatas=None, **kwargs)[source]
Add texts data to an existing index.
Parameters
texts (Iterable[str]) –
metadatas (Optional[List[dict]]) –
kwargs (Any) –
Return type
List[str]
similarity_search(query, k=4, **kwargs)[source]
Returns the most similar indexed documents to the query text.
Parameters
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
kwargs (Any) –
Returns
A list of documents that are most similar to the query text.
Return type
List[Document]


Return type
List[Document]
classmethod from_texts(texts, embedding, metadatas=None, index_name='langchain', content_key='content', metadata_key='metadata', **kwargs)[source]
Return VectorStore initialized from texts and embeddings.
Parameters
texts (List[str]) –
embedding (langchain.embeddings.base.Embeddings) –
metadatas (Optional[List[dict]]) –
index_name (str) –
content_key (str) –
metadata_key (str) –
kwargs (Any) –
Return type
langchain.vectorstores.tair.Tair
classmethod from_documents(documents, embedding, metadatas=None, index_name='langchain', content_key='content', metadata_key='metadata', **kwargs)[source]
Return VectorStore initialized from documents and embeddings.
Parameters
documents (List[langchain.schema.Document]) –
embedding (langchain.embeddings.base.Embeddings) –
metadatas (Optional[List[dict]]) –
index_name (str) –
content_key (str) –
metadata_key (str) –
kwargs (Any) –
Return type
langchain.vectorstores.tair.Tair
static drop_index(index_name='langchain', **kwargs)[source]
Drop an existing index.
Parameters
index_name (str) – Name of the index to drop.
kwargs (Any) –
Returns
True if the index is dropped successfully.
Return type
bool
classmethod from_existing_index(embedding, index_name='langchain', content_key='content', metadata_key='metadata', **kwargs)[source]
Connect to an existing Tair index.
Parameters
embedding (langchain.embeddings.base.Embeddings) –
index_name (str) –
content_key (str) –


index_name (str) –
content_key (str) –
metadata_key (str) –
kwargs (Any) –
Return type
langchain.vectorstores.tair.Tair
class langchain.vectorstores.Tigris(client, embeddings, index_name)[source]
Bases: langchain.vectorstores.base.VectorStore
Parameters
client (TigrisClient) –
embeddings (Embeddings) –
index_name (str) –
property search_index: TigrisVectorStore
add_texts(texts, metadatas=None, ids=None, **kwargs)[source]
Run more texts through the embeddings and add to the vectorstore.
Parameters
texts (Iterable[str]) – Iterable of strings to add to the vectorstore.
metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts.
ids (Optional[List[str]]) – Optional list of ids for documents.
Ids will be autogenerated if not provided.
kwargs (Any) – vectorstore specific parameters
Returns
List of ids from adding the texts into the vectorstore.
Return type
List[str]
similarity_search(query, k=4, filter=None, **kwargs)[source]
Return docs most similar to query.
Parameters
query (str) –
k (int) –
filter (Optional[TigrisFilter]) –
kwargs (Any) –
Return type
List[Document]
similarity_search_with_score(query, k=4, filter=None)[source]
Run similarity search with Chroma with distance.
Parameters
query (str) – Query text to search for.
k (int) – Number of results to return. Defaults to 4.
filter (Optional[TigrisFilter]) – Filter by metadata. Defaults to None.
Returns


filter (Optional[TigrisFilter]) – Filter by metadata. Defaults to None.
Returns
List of documents most similar to the querytext with distance in float.
Return type
List[Tuple[Document, float]]
classmethod from_texts(texts, embedding, metadatas=None, ids=None, client=None, index_name=None, **kwargs)[source]
Return VectorStore initialized from texts and embeddings.
Parameters
texts (List[str]) –
embedding (Embeddings) –
metadatas (Optional[List[dict]]) –
ids (Optional[List[str]]) –
client (Optional[TigrisClient]) –
index_name (Optional[str]) –
kwargs (Any) –
Return type
Tigris
class langchain.vectorstores.Typesense(typesense_client, embedding, *, typesense_collection_name=None, text_key='text')[source]
Bases: langchain.vectorstores.base.VectorStore
Wrapper around Typesense vector search.
To use, you should have the typesense python package installed.
Example
from langchain.embedding.openai import OpenAIEmbeddings
from langchain.vectorstores import Typesense
import typesense
node = {
    "host": "localhost",  # For Typesense Cloud use xxx.a1.typesense.net
    "port": "8108",       # For Typesense Cloud use 443
    "protocol": "http"    # For Typesense Cloud use https
}
typesense_client = typesense.Client(
    {
      "nodes": [node],
      "api_key": "<API_KEY>",
      "connection_timeout_seconds": 2
    }
)
typesense_collection_name = "langchain-memory"
embedding = OpenAIEmbeddings()
vectorstore = Typesense(
    typesense_client=typesense_client,
    embedding=embedding,


typesense_client=typesense_client,
    embedding=embedding,
    typesense_collection_name=typesense_collection_name,
    text_key="text",
)
Parameters
typesense_client (Client) –
embedding (Embeddings) –
typesense_collection_name (Optional[str]) –
text_key (str) –
add_texts(texts, metadatas=None, ids=None, **kwargs)[source]
Run more texts through the embedding and add to the vectorstore.
Parameters
texts (Iterable[str]) – Iterable of strings to add to the vectorstore.
metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts.
ids (Optional[List[str]]) – Optional list of ids to associate with the texts.
kwargs (Any) –
Returns
List of ids from adding the texts into the vectorstore.
Return type
List[str]
similarity_search_with_score(query, k=10, filter='')[source]
Return typesense documents most similar to query, along with scores.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 10.
Minimum 10 results would be returned.
filter (Optional[str]) – typesense filter_by expression to filter documents on
Returns
List of Documents most similar to the query and score for each
Return type
List[Tuple[langchain.schema.Document, float]]
similarity_search(query, k=10, filter='', **kwargs)[source]
Return typesense documents most similar to query.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 10.
Minimum 10 results would be returned.


Minimum 10 results would be returned.
filter (Optional[str]) – typesense filter_by expression to filter documents on
kwargs (Any) –
Returns
List of Documents most similar to the query and score for each
Return type
List[langchain.schema.Document]
classmethod from_client_params(embedding, *, host='localhost', port='8108', protocol='http', typesense_api_key=None, connection_timeout_seconds=2, **kwargs)[source]
Initialize Typesense directly from client parameters.
Example
from langchain.embedding.openai import OpenAIEmbeddings
from langchain.vectorstores import Typesense
# Pass in typesense_api_key as kwarg or set env var "TYPESENSE_API_KEY".
vectorstore = Typesense(
    OpenAIEmbeddings(),
    host="localhost",
    port="8108",
    protocol="http",
    typesense_collection_name="langchain-memory",
)
Parameters
embedding (langchain.embeddings.base.Embeddings) –
host (str) –
port (Union[str, int]) –
protocol (str) –
typesense_api_key (Optional[str]) –
connection_timeout_seconds (int) –
kwargs (Any) –
Return type
langchain.vectorstores.typesense.Typesense
classmethod from_texts(texts, embedding, metadatas=None, ids=None, typesense_client=None, typesense_client_params=None, typesense_collection_name=None, text_key='text', **kwargs)[source]
Construct Typesense wrapper from raw text.
Parameters
texts (List[str]) –
embedding (Embeddings) –
metadatas (Optional[List[dict]]) –
ids (Optional[List[str]]) –
typesense_client (Optional[Client]) –
typesense_client_params (Optional[dict]) –


typesense_client_params (Optional[dict]) –
typesense_collection_name (Optional[str]) –
text_key (str) –
kwargs (Any) –
Return type
Typesense
class langchain.vectorstores.Vectara(vectara_customer_id=None, vectara_corpus_id=None, vectara_api_key=None)[source]
Bases: langchain.vectorstores.base.VectorStore
Implementation of Vector Store using Vectara (https://vectara.com).
.. rubric:: Example
from langchain.vectorstores import Vectara
vectorstore = Vectara(
    vectara_customer_id=vectara_customer_id,
    vectara_corpus_id=vectara_corpus_id,
    vectara_api_key=vectara_api_key
)
Parameters
vectara_customer_id (Optional[str]) –
vectara_corpus_id (Optional[str]) –
vectara_api_key (Optional[str]) –
add_texts(texts, metadatas=None, **kwargs)[source]
Run more texts through the embeddings and add to the vectorstore.
Parameters
texts (Iterable[str]) – Iterable of strings to add to the vectorstore.
metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts.
kwargs (Any) –
Returns
List of ids from adding the texts into the vectorstore.
Return type
List[str]
similarity_search_with_score(query, k=5, lambda_val=0.025, filter=None, n_sentence_context=0, **kwargs)[source]
Return Vectara documents most similar to query, along with scores.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 5.
lambda_val (float) – lexical match parameter for hybrid search.


lambda_val (float) – lexical match parameter for hybrid search.
filter (Optional[str]) – Dictionary of argument(s) to filter on metadata. For example a
filter can be “doc.rating > 3.0 and part.lang = ‘deu’”} see
https://docs.vectara.com/docs/search-apis/sql/filter-overview
for more details.
n_sentence_context (int) – number of sentences before/after the matching segment
to add
kwargs (Any) –
Returns
List of Documents most similar to the query and score for each.
Return type
List[Tuple[langchain.schema.Document, float]]
similarity_search(query, k=5, lambda_val=0.025, filter=None, n_sentence_context=0, **kwargs)[source]
Return Vectara documents most similar to query, along with scores.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 5.
filter (Optional[str]) – Dictionary of argument(s) to filter on metadata. For example a
filter can be “doc.rating > 3.0 and part.lang = ‘deu’”} see
https://docs.vectara.com/docs/search-apis/sql/filter-overview for more
details.
n_sentence_context (int) – number of sentences before/after the matching segment
to add
lambda_val (float) –
kwargs (Any) –
Returns
List of Documents most similar to the query
Return type
List[langchain.schema.Document]
classmethod from_texts(texts, embedding=None, metadatas=None, **kwargs)[source]
Construct Vectara wrapper from raw documents.
This is intended to be a quick way to get started.
.. rubric:: Example
from langchain import Vectara


.. rubric:: Example
from langchain import Vectara
vectara = Vectara.from_texts(
    texts,
    vectara_customer_id=customer_id,
    vectara_corpus_id=corpus_id,
    vectara_api_key=api_key,
)
Parameters
texts (List[str]) –
embedding (Optional[langchain.embeddings.base.Embeddings]) –
metadatas (Optional[List[dict]]) –
kwargs (Any) –
Return type
langchain.vectorstores.vectara.Vectara
as_retriever(**kwargs)[source]
Parameters
kwargs (Any) –
Return type
langchain.vectorstores.vectara.VectaraRetriever
class langchain.vectorstores.VectorStore[source]
Bases: abc.ABC
Interface for vector stores.
abstract add_texts(texts, metadatas=None, **kwargs)[source]
Run more texts through the embeddings and add to the vectorstore.
Parameters
texts (Iterable[str]) – Iterable of strings to add to the vectorstore.
metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts.
kwargs (Any) – vectorstore specific parameters
Returns
List of ids from adding the texts into the vectorstore.
Return type
List[str]
delete(ids)[source]
Delete by vector ID.
Parameters
ids (List[str]) – List of ids to delete.
Returns
True if deletion is successful,
False otherwise, None if not implemented.
Return type
Optional[bool]
async aadd_texts(texts, metadatas=None, **kwargs)[source]
Run more texts through the embeddings and add to the vectorstore.
Parameters
texts (Iterable[str]) –
metadatas (Optional[List[dict]]) –


texts (Iterable[str]) –
metadatas (Optional[List[dict]]) –
kwargs (Any) –
Return type
List[str]
add_documents(documents, **kwargs)[source]
Run more documents through the embeddings and add to the vectorstore.
Parameters
(List[Document] (documents) – Documents to add to the vectorstore.
documents (List[langchain.schema.Document]) –
kwargs (Any) –
Returns
List of IDs of the added texts.
Return type
List[str]
async aadd_documents(documents, **kwargs)[source]
Run more documents through the embeddings and add to the vectorstore.
Parameters
(List[Document] (documents) – Documents to add to the vectorstore.
documents (List[langchain.schema.Document]) –
kwargs (Any) –
Returns
List of IDs of the added texts.
Return type
List[str]
search(query, search_type, **kwargs)[source]
Return docs most similar to query using specified search type.
Parameters
query (str) –
search_type (str) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
async asearch(query, search_type, **kwargs)[source]
Return docs most similar to query using specified search type.
Parameters
query (str) –
search_type (str) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
abstract similarity_search(query, k=4, **kwargs)[source]
Return docs most similar to query.
Parameters
query (str) –
k (int) –
kwargs (Any) –
Return type
List[langchain.schema.Document]


kwargs (Any) –
Return type
List[langchain.schema.Document]
similarity_search_with_relevance_scores(query, k=4, **kwargs)[source]
Return docs and relevance scores in the range [0, 1].
0 is dissimilar, 1 is most similar.
Parameters
query (str) – input text
k (int) – Number of Documents to return. Defaults to 4.
**kwargs – kwargs to be passed to similarity search. Should include:
score_threshold: Optional, a floating point value between 0 to 1 to
filter the resulting set of retrieved docs
kwargs (Any) –
Returns
List of Tuples of (doc, similarity_score)
Return type
List[Tuple[langchain.schema.Document, float]]
async asimilarity_search_with_relevance_scores(query, k=4, **kwargs)[source]
Return docs most similar to query.
Parameters
query (str) –
k (int) –
kwargs (Any) –
Return type
List[Tuple[langchain.schema.Document, float]]
async asimilarity_search(query, k=4, **kwargs)[source]
Return docs most similar to query.
Parameters
query (str) –
k (int) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
similarity_search_by_vector(embedding, k=4, **kwargs)[source]
Return docs most similar to embedding vector.
Parameters
embedding (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
kwargs (Any) –
Returns
List of Documents most similar to the query vector.
Return type
List[langchain.schema.Document]


Return type
List[langchain.schema.Document]
async asimilarity_search_by_vector(embedding, k=4, **kwargs)[source]
Return docs most similar to embedding vector.
Parameters
embedding (List[float]) –
k (int) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
max_marginal_relevance_search(query, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – Number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
kwargs (Any) –
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[langchain.schema.Document]
async amax_marginal_relevance_search(query, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.
Parameters
query (str) –
k (int) –
fetch_k (int) –
lambda_mult (float) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
max_marginal_relevance_search_by_vector(embedding, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]


Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
embedding (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – Number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
kwargs (Any) –
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[langchain.schema.Document]
async amax_marginal_relevance_search_by_vector(embedding, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.
Parameters
embedding (List[float]) –
k (int) –
fetch_k (int) –
lambda_mult (float) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
classmethod from_documents(documents, embedding, **kwargs)[source]
Return VectorStore initialized from documents and embeddings.
Parameters
documents (List[langchain.schema.Document]) –
embedding (langchain.embeddings.base.Embeddings) –
kwargs (Any) –
Return type
langchain.vectorstores.base.VST
async classmethod afrom_documents(documents, embedding, **kwargs)[source]
Return VectorStore initialized from documents and embeddings.
Parameters
documents (List[langchain.schema.Document]) –
embedding (langchain.embeddings.base.Embeddings) –
kwargs (Any) –
Return type


kwargs (Any) –
Return type
langchain.vectorstores.base.VST
abstract classmethod from_texts(texts, embedding, metadatas=None, **kwargs)[source]
Return VectorStore initialized from texts and embeddings.
Parameters
texts (List[str]) –
embedding (langchain.embeddings.base.Embeddings) –
metadatas (Optional[List[dict]]) –
kwargs (Any) –
Return type
langchain.vectorstores.base.VST
async classmethod afrom_texts(texts, embedding, metadatas=None, **kwargs)[source]
Return VectorStore initialized from texts and embeddings.
Parameters
texts (List[str]) –
embedding (langchain.embeddings.base.Embeddings) –
metadatas (Optional[List[dict]]) –
kwargs (Any) –
Return type
langchain.vectorstores.base.VST
as_retriever(**kwargs)[source]
Parameters
kwargs (Any) –
Return type
langchain.vectorstores.base.VectorStoreRetriever
class langchain.vectorstores.Weaviate(client, index_name, text_key, embedding=None, attributes=None, relevance_score_fn=<function _default_score_normalizer>, by_text=True)[source]
Bases: langchain.vectorstores.base.VectorStore
Wrapper around Weaviate vector database.
To use, you should have the weaviate-client python package installed.
Example
import weaviate
from langchain.vectorstores import Weaviate
client = weaviate.Client(url=os.environ["WEAVIATE_URL"], ...)
weaviate = Weaviate(client, index_name, text_key)
Parameters
client (Any) –
index_name (str) –
text_key (str) –
embedding (Optional[Embeddings]) –
attributes (Optional[List[str]]) –


embedding (Optional[Embeddings]) –
attributes (Optional[List[str]]) –
relevance_score_fn (Optional[Callable[[float], float]]) –
by_text (bool) –
add_texts(texts, metadatas=None, **kwargs)[source]
Upload texts with metadata (properties) to Weaviate.
Parameters
texts (Iterable[str]) –
metadatas (Optional[List[dict]]) –
kwargs (Any) –
Return type
List[str]
similarity_search(query, k=4, **kwargs)[source]
Return docs most similar to query.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
kwargs (Any) –
Returns
List of Documents most similar to the query.
Return type
List[langchain.schema.Document]
similarity_search_by_text(query, k=4, **kwargs)[source]
Return docs most similar to query.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
kwargs (Any) –
Returns
List of Documents most similar to the query.
Return type
List[langchain.schema.Document]
similarity_search_by_vector(embedding, k=4, **kwargs)[source]
Look up similar documents by embedding vector in Weaviate.
Parameters
embedding (List[float]) –
k (int) –
kwargs (Any) –
Return type
List[langchain.schema.Document]
max_marginal_relevance_search(query, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.


Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – Number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
kwargs (Any) –
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[langchain.schema.Document]
max_marginal_relevance_search_by_vector(embedding, k=4, fetch_k=20, lambda_mult=0.5, **kwargs)[source]
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
embedding (List[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.
lambda_mult (float) – Number between 0 and 1 that determines the degree
of diversity among the results with 0 corresponding
to maximum diversity and 1 to minimum diversity.
Defaults to 0.5.
kwargs (Any) –
Returns
List of Documents selected by maximal marginal relevance.
Return type
List[langchain.schema.Document]
similarity_search_with_score(query, k=4, **kwargs)[source]
Return list of documents most similar to the query
text and cosine distance in float for each.
Lower score represents more similarity.
Parameters


text and cosine distance in float for each.
Lower score represents more similarity.
Parameters
query (str) –
k (int) –
kwargs (Any) –
Return type
List[Tuple[langchain.schema.Document, float]]
classmethod from_texts(texts, embedding, metadatas=None, **kwargs)[source]
Construct Weaviate wrapper from raw documents.
This is a user-friendly interface that:
Embeds documents.
Creates a new index for the embeddings in the Weaviate instance.
Adds the documents to the newly created Weaviate index.
This is intended to be a quick way to get started.
Example
from langchain.vectorstores.weaviate import Weaviate
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
weaviate = Weaviate.from_texts(
    texts,
    embeddings,
    weaviate_url="http://localhost:8080"
)
Parameters
texts (List[str]) –
embedding (langchain.embeddings.base.Embeddings) –
metadatas (Optional[List[dict]]) –
kwargs (Any) –
Return type
langchain.vectorstores.weaviate.Weaviate
delete(ids)[source]
Delete by vector IDs.
Parameters
ids (List[str]) – List of ids to delete.
Return type
None


LLMs
Wrappers on top of large language models APIs.
class langchain.llms.AI21(*, cache=None, verbose=None, callbacks=None, callback_manager=None, tags=None, model='j2-jumbo-instruct', temperature=0.7, maxTokens=256, minTokens=0, topP=1.0, presencePenalty=AI21PenaltyData(scale=0, applyToWhitespaces=True, applyToPunctuations=True, applyToNumbers=True, applyToStopwords=True, applyToEmojis=True), countPenalty=AI21PenaltyData(scale=0, applyToWhitespaces=True, applyToPunctuations=True, applyToNumbers=True, applyToStopwords=True, applyToEmojis=True), frequencyPenalty=AI21PenaltyData(scale=0, applyToWhitespaces=True, applyToPunctuations=True, applyToNumbers=True, applyToStopwords=True, applyToEmojis=True), numResults=1, logitBias=None, ai21_api_key=None, stop=None, base_url=None)[source]
Bases: langchain.llms.base.LLM
Wrapper around AI21 large language models.
To use, you should have the environment variable AI21_API_KEY
set with your API key.
Example
from langchain.llms import AI21
ai21 = AI21(model="j2-jumbo-instruct")
Parameters
cache (Optional[bool]) –
verbose (bool) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
tags (Optional[List[str]]) –
model (str) –
temperature (float) –
maxTokens (int) –
minTokens (int) –


maxTokens (int) –
minTokens (int) –
topP (float) –
presencePenalty (langchain.llms.ai21.AI21PenaltyData) –
countPenalty (langchain.llms.ai21.AI21PenaltyData) –
frequencyPenalty (langchain.llms.ai21.AI21PenaltyData) –
numResults (int) –
logitBias (Optional[Dict[str, float]]) –
ai21_api_key (Optional[str]) –
stop (Optional[List[str]]) –
base_url (Optional[str]) –
Return type
None
attribute base_url: Optional[str] = None
Base url to use, if None decides based on model name.
attribute countPenalty: langchain.llms.ai21.AI21PenaltyData = AI21PenaltyData(scale=0, applyToWhitespaces=True, applyToPunctuations=True, applyToNumbers=True, applyToStopwords=True, applyToEmojis=True)
Penalizes repeated tokens according to count.
attribute frequencyPenalty: langchain.llms.ai21.AI21PenaltyData = AI21PenaltyData(scale=0, applyToWhitespaces=True, applyToPunctuations=True, applyToNumbers=True, applyToStopwords=True, applyToEmojis=True)
Penalizes repeated tokens according to frequency.
attribute logitBias: Optional[Dict[str, float]] = None
Adjust the probability of specific tokens being generated.
attribute maxTokens: int = 256
The maximum number of tokens to generate in the completion.
attribute minTokens: int = 0
The minimum number of tokens to generate in the completion.
attribute model: str = 'j2-jumbo-instruct'
Model name to use.


Model name to use.
attribute numResults: int = 1
How many completions to generate for each prompt.
attribute presencePenalty: langchain.llms.ai21.AI21PenaltyData = AI21PenaltyData(scale=0, applyToWhitespaces=True, applyToPunctuations=True, applyToNumbers=True, applyToStopwords=True, applyToEmojis=True)
Penalizes repeated tokens.
attribute tags: Optional[List[str]] = None
Tags to add to the run trace.
attribute temperature: float = 0.7
What sampling temperature to use.
attribute topP: float = 1.0
Total probability mass of tokens to consider at each step.
attribute verbose: bool [Optional]
Whether to print out response text.
__call__(prompt, stop=None, callbacks=None, **kwargs)
Check Cache and run the LLM on the given prompt and input.
Parameters
prompt (str) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
str
async agenerate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async agenerate_prompt(prompts, stop=None, callbacks=None, **kwargs)


async agenerate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async apredict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
async apredict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
classmethod construct(_fields_set=None, **values)
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
Parameters
_fields_set (Optional[SetStr]) –
values (Any) –
Return type
Model
copy(*, include=None, exclude=None, update=None, deep=False)
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model


exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
Returns
new model instance
Return type
Model
dict(**kwargs)
Return a dictionary of the LLM.
Parameters
kwargs (Any) –
Return type
Dict
generate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
generate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
get_num_tokens(text)
Get the number of tokens present in the text.
Parameters
text (str) –
Return type
int
get_num_tokens_from_messages(messages)
Get the number of tokens in the message.
Parameters


Get the number of tokens in the message.
Parameters
messages (List[langchain.schema.BaseMessage]) –
Return type
int
get_token_ids(text)
Get the token present in the text.
Parameters
text (str) –
Return type
List[int]
json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
by_alias (bool) –
skip_defaults (Optional[bool]) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Optional[Callable[[Any], Any]]) –
models_as_dict (bool) –
dumps_kwargs (Any) –
Return type
unicode
predict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
predict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
save(file_path)
Save the LLM.
Parameters


save(file_path)
Save the LLM.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the LLM to.
Return type
None
Example:
.. code-block:: python
llm.save(file_path=”path/llm.yaml”)
classmethod update_forward_refs(**localns)
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) –
Return type
None
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.


property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.llms.AlephAlpha(*, cache=None, verbose=None, callbacks=None, callback_manager=None, tags=None, client=None, model='luminous-base', maximum_tokens=64, temperature=0.0, top_k=0, top_p=0.0, presence_penalty=0.0, frequency_penalty=0.0, repetition_penalties_include_prompt=False, use_multiplicative_presence_penalty=False, penalty_bias=None, penalty_exceptions=None, penalty_exceptions_include_stop_sequences=None, best_of=None, n=1, logit_bias=None, log_probs=None, tokens=False, disable_optimizations=False, minimum_tokens=0, echo=False, use_multiplicative_frequency_penalty=False, sequence_penalty=0.0, sequence_penalty_min_length=2, use_multiplicative_sequence_penalty=False, completion_bias_inclusion=None, completion_bias_inclusion_first_token_only=False, completion_bias_exclusion=None, completion_bias_exclusion_first_token_only=False, contextual_control_threshold=None, control_log_additive=True, repetition_penalties_include_completion=True, raw_completion=False, aleph_alpha_api_key=None, stop_sequences=None)[source]
Bases: langchain.llms.base.LLM
Wrapper around Aleph Alpha large language models.
To use, you should have the aleph_alpha_client python package installed, and the
environment variable ALEPH_ALPHA_API_KEY set with your API key, or pass
it as a named parameter to the constructor.
Parameters are explained more in depth here:
https://github.com/Aleph-Alpha/aleph-alpha-client/blob/c14b7dd2b4325c7da0d6a119f6e76385800e097b/aleph_alpha_client/completion.py#L10
Example
from langchain.llms import AlephAlpha


Example
from langchain.llms import AlephAlpha
aleph_alpha = AlephAlpha(aleph_alpha_api_key="my-api-key")
Parameters
cache (Optional[bool]) –
verbose (bool) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
tags (Optional[List[str]]) –
client (Any) –
model (Optional[str]) –
maximum_tokens (int) –
temperature (float) –
top_k (int) –
top_p (float) –
presence_penalty (float) –
frequency_penalty (float) –
repetition_penalties_include_prompt (Optional[bool]) –
use_multiplicative_presence_penalty (Optional[bool]) –
penalty_bias (Optional[str]) –
penalty_exceptions (Optional[List[str]]) –
penalty_exceptions_include_stop_sequences (Optional[bool]) –
best_of (Optional[int]) –
n (int) –
logit_bias (Optional[Dict[int, float]]) –
log_probs (Optional[int]) –
tokens (Optional[bool]) –
disable_optimizations (Optional[bool]) –
minimum_tokens (Optional[int]) –
echo (bool) –
use_multiplicative_frequency_penalty (bool) –
sequence_penalty (float) –
sequence_penalty_min_length (int) –
use_multiplicative_sequence_penalty (bool) –
completion_bias_inclusion (Optional[Sequence[str]]) –
completion_bias_inclusion_first_token_only (bool) –
completion_bias_exclusion (Optional[Sequence[str]]) –
completion_bias_exclusion_first_token_only (bool) –


completion_bias_exclusion_first_token_only (bool) –
contextual_control_threshold (Optional[float]) –
control_log_additive (Optional[bool]) –
repetition_penalties_include_completion (bool) –
raw_completion (bool) –
aleph_alpha_api_key (Optional[str]) –
stop_sequences (Optional[List[str]]) –
Return type
None
attribute aleph_alpha_api_key: Optional[str] = None
API key for Aleph Alpha API.
attribute best_of: Optional[int] = None
returns the one with the “best of” results
(highest log probability per token)
attribute completion_bias_exclusion_first_token_only: bool = False
Only consider the first token for the completion_bias_exclusion.
attribute contextual_control_threshold: Optional[float] = None
If set to None, attention control parameters only apply to those tokens that have
explicitly been set in the request.
If set to a non-None value, control parameters are also applied to similar tokens.
attribute control_log_additive: Optional[bool] = True
True: apply control by adding the log(control_factor) to attention scores.
False: (attention_scores - - attention_scores.min(-1)) * control_factor
attribute echo: bool = False
Echo the prompt in the completion.
attribute frequency_penalty: float = 0.0
Penalizes repeated tokens according to frequency.
attribute log_probs: Optional[int] = None
Number of top log probabilities to be returned for each generated token.
attribute logit_bias: Optional[Dict[int, float]] = None
The logit bias allows to influence the likelihood of generating tokens.
attribute maximum_tokens: int = 64
The maximum number of tokens to be generated.


The maximum number of tokens to be generated.
attribute minimum_tokens: Optional[int] = 0
Generate at least this number of tokens.
attribute model: Optional[str] = 'luminous-base'
Model name to use.
attribute n: int = 1
How many completions to generate for each prompt.
attribute penalty_bias: Optional[str] = None
Penalty bias for the completion.
attribute penalty_exceptions: Optional[List[str]] = None
List of strings that may be generated without penalty,
regardless of other penalty settings
attribute penalty_exceptions_include_stop_sequences: Optional[bool] = None
Should stop_sequences be included in penalty_exceptions.
attribute presence_penalty: float = 0.0
Penalizes repeated tokens.
attribute raw_completion: bool = False
Force the raw completion of the model to be returned.
attribute repetition_penalties_include_completion: bool = True
Flag deciding whether presence penalty or frequency penalty
are updated from the completion.
attribute repetition_penalties_include_prompt: Optional[bool] = False
Flag deciding whether presence penalty or frequency penalty are
updated from the prompt.
attribute stop_sequences: Optional[List[str]] = None
Stop sequences to use.
attribute tags: Optional[List[str]] = None
Tags to add to the run trace.
attribute temperature: float = 0.0
A non-negative float that tunes the degree of randomness in generation.
attribute tokens: Optional[bool] = False
return tokens of completion.
attribute top_k: int = 0
Number of most likely tokens to consider at each step.
attribute top_p: float = 0.0
Total probability mass of tokens to consider at each step.


Total probability mass of tokens to consider at each step.
attribute use_multiplicative_presence_penalty: Optional[bool] = False
Flag deciding whether presence penalty is applied
multiplicatively (True) or additively (False).
attribute verbose: bool [Optional]
Whether to print out response text.
__call__(prompt, stop=None, callbacks=None, **kwargs)
Check Cache and run the LLM on the given prompt and input.
Parameters
prompt (str) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
str
async agenerate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async agenerate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async apredict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –


Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
async apredict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
classmethod construct(_fields_set=None, **values)
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
Parameters
_fields_set (Optional[SetStr]) –
values (Any) –
Return type
Model
copy(*, include=None, exclude=None, update=None, deep=False)
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
Returns
new model instance
Return type
Model
dict(**kwargs)
Return a dictionary of the LLM.
Parameters
kwargs (Any) –
Return type
Dict


Parameters
kwargs (Any) –
Return type
Dict
generate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
generate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
get_num_tokens(text)
Get the number of tokens present in the text.
Parameters
text (str) –
Return type
int
get_num_tokens_from_messages(messages)
Get the number of tokens in the message.
Parameters
messages (List[langchain.schema.BaseMessage]) –
Return type
int
get_token_ids(text)
Get the token present in the text.
Parameters
text (str) –
Return type
List[int]
json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)
Generate a JSON representation of the model, include and exclude arguments as per dict().


Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
by_alias (bool) –
skip_defaults (Optional[bool]) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Optional[Callable[[Any], Any]]) –
models_as_dict (bool) –
dumps_kwargs (Any) –
Return type
unicode
predict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
predict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
save(file_path)
Save the LLM.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the LLM to.
Return type
None
Example:
.. code-block:: python
llm.save(file_path=”path/llm.yaml”)
classmethod update_forward_refs(**localns)
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) –
Return type
None
property lc_attributes: Dict
Return a list of attribute names that should be included in the


Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.llms.AmazonAPIGateway(*, cache=None, verbose=None, callbacks=None, callback_manager=None, tags=None, api_url, model_kwargs=None, content_handler=<langchain.llms.amazon_api_gateway.ContentHandlerAmazonAPIGateway object>)[source]
Bases: langchain.llms.base.LLM
Wrapper around custom Amazon API Gateway
Parameters
cache (Optional[bool]) –
verbose (bool) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
tags (Optional[List[str]]) –
api_url (str) –
model_kwargs (Optional[Dict]) –
content_handler (langchain.llms.amazon_api_gateway.ContentHandlerAmazonAPIGateway) –
Return type
None
attribute api_url: str [Required]
API Gateway URL
attribute content_handler: langchain.llms.amazon_api_gateway.ContentHandlerAmazonAPIGateway = <langchain.llms.amazon_api_gateway.ContentHandlerAmazonAPIGateway object>
The content handler class that provides an input and
output transform functions to handle formats between LLM
and the endpoint.


output transform functions to handle formats between LLM
and the endpoint.
attribute model_kwargs: Optional[Dict] = None
Key word arguments to pass to the model.
attribute tags: Optional[List[str]] = None
Tags to add to the run trace.
attribute verbose: bool [Optional]
Whether to print out response text.
__call__(prompt, stop=None, callbacks=None, **kwargs)
Check Cache and run the LLM on the given prompt and input.
Parameters
prompt (str) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
str
async agenerate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async agenerate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async apredict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters


Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.llms.Anthropic(*, client=None, model='claude-v1', max_tokens_to_sample=256, temperature=None, top_k=None, top_p=None, streaming=False, default_request_timeout=None, anthropic_api_url=None, anthropic_api_key=None, HUMAN_PROMPT=None, AI_PROMPT=None, count_tokens=None, cache=None, verbose=None, callbacks=None, callback_manager=None, tags=None)[source]
Bases: langchain.llms.base.LLM, langchain.llms.anthropic._AnthropicCommon
Wrapper around Anthropic’s large language models.
To use, you should have the anthropic python package installed, and the
environment variable ANTHROPIC_API_KEY set with your API key, or pass
it as a named parameter to the constructor.
Example
import anthropic
from langchain.llms import Anthropic
model = Anthropic(model="<model_name>", anthropic_api_key="my-api-key")
# Simplest invocation, automatically wrapped with HUMAN_PROMPT
# and AI_PROMPT.
response = model("What are the biggest risks facing humanity?")
# Or if you want to use the chat mode, build a few-shot-prompt, or


# Or if you want to use the chat mode, build a few-shot-prompt, or
# put words in the Assistant's mouth, use HUMAN_PROMPT and AI_PROMPT:
raw_prompt = "What are the biggest risks facing humanity?"
prompt = f"{anthropic.HUMAN_PROMPT} {prompt}{anthropic.AI_PROMPT}"
response = model(prompt)
Parameters
client (Any) –
model (str) –
max_tokens_to_sample (int) –
temperature (Optional[float]) –
top_k (Optional[int]) –
top_p (Optional[float]) –
streaming (bool) –
default_request_timeout (Optional[Union[float, Tuple[float, float]]]) –
anthropic_api_url (Optional[str]) –
anthropic_api_key (Optional[str]) –
HUMAN_PROMPT (Optional[str]) –
AI_PROMPT (Optional[str]) –
count_tokens (Optional[Callable[[str], int]]) –
cache (Optional[bool]) –
verbose (bool) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
tags (Optional[List[str]]) –
Return type
None
attribute default_request_timeout: Optional[Union[float, Tuple[float, float]]] = None
Timeout for requests to Anthropic Completion API. Default is 600 seconds.
attribute max_tokens_to_sample: int = 256
Denotes the number of tokens to predict per generation.
attribute model: str = 'claude-v1'
Model name to use.
attribute streaming: bool = False
Whether to stream the results.
attribute tags: Optional[List[str]] = None


Whether to stream the results.
attribute tags: Optional[List[str]] = None
Tags to add to the run trace.
attribute temperature: Optional[float] = None
A non-negative float that tunes the degree of randomness in generation.
attribute top_k: Optional[int] = None
Number of most likely tokens to consider at each step.
attribute top_p: Optional[float] = None
Total probability mass of tokens to consider at each step.
attribute verbose: bool [Optional]
Whether to print out response text.
__call__(prompt, stop=None, callbacks=None, **kwargs)
Check Cache and run the LLM on the given prompt and input.
Parameters
prompt (str) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
str
async agenerate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async agenerate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –


kwargs (Any) –
Return type
langchain.schema.LLMResult
async apredict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
async apredict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
classmethod construct(_fields_set=None, **values)
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
Parameters
_fields_set (Optional[SetStr]) –
values (Any) –
Return type
Model
copy(*, include=None, exclude=None, update=None, deep=False)
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
Returns
new model instance
Return type
Model
dict(**kwargs)


Returns
new model instance
Return type
Model
dict(**kwargs)
Return a dictionary of the LLM.
Parameters
kwargs (Any) –
Return type
Dict
generate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
generate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
get_num_tokens(text)[source]
Calculate number of tokens.
Parameters
text (str) –
Return type
int
get_num_tokens_from_messages(messages)
Get the number of tokens in the message.
Parameters
messages (List[langchain.schema.BaseMessage]) –
Return type
int
get_token_ids(text)
Get the token present in the text.
Parameters
text (str) –
Return type
List[int]
json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)


Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
by_alias (bool) –
skip_defaults (Optional[bool]) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Optional[Callable[[Any], Any]]) –
models_as_dict (bool) –
dumps_kwargs (Any) –
Return type
unicode
predict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
predict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
save(file_path)
Save the LLM.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the LLM to.
Return type
None
Example:
.. code-block:: python
llm.save(file_path=”path/llm.yaml”)
stream(prompt, stop=None)[source]
Call Anthropic completion_stream and return the resulting generator.
BETA: this is a beta feature while we figure out the right abstraction.
Once that happens, this interface could change.
Parameters
prompt (str) – The prompt to pass into the model.


Parameters
prompt (str) – The prompt to pass into the model.
stop (Optional[List[str]]) – Optional list of stop words to use when generating.
Returns
A generator representing the stream of tokens from Anthropic.
Return type
Generator
Example
prompt = "Write a poem about a stream."
prompt = f"\n\nHuman: {prompt}\n\nAssistant:"
generator = anthropic.stream(prompt)
for token in generator:
    yield token
classmethod update_forward_refs(**localns)
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) –
Return type
None
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.llms.Anyscale(*, cache=None, verbose=None, callbacks=None, callback_manager=None, tags=None, model_kwargs=None, anyscale_service_url=None, anyscale_service_route=None, anyscale_service_token=None)[source]
Bases: langchain.llms.base.LLM
Wrapper around Anyscale Services.
To use, you should have the environment variable ANYSCALE_SERVICE_URL,
ANYSCALE_SERVICE_ROUTE and ANYSCALE_SERVICE_TOKEN set with your Anyscale
Service, or pass it as a named parameter to the constructor.
Example


Service, or pass it as a named parameter to the constructor.
Example
from langchain.llms import Anyscale
anyscale = Anyscale(anyscale_service_url="SERVICE_URL",
                    anyscale_service_route="SERVICE_ROUTE",
                    anyscale_service_token="SERVICE_TOKEN")
# Use Ray for distributed processing
import ray
prompt_list=[]
@ray.remote
def send_query(llm, prompt):
    resp = llm(prompt)
    return resp
futures = [send_query.remote(anyscale, prompt) for prompt in prompt_list]
results = ray.get(futures)
Parameters
cache (Optional[bool]) –
verbose (bool) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
tags (Optional[List[str]]) –
model_kwargs (Optional[dict]) –
anyscale_service_url (Optional[str]) –
anyscale_service_route (Optional[str]) –
anyscale_service_token (Optional[str]) –
Return type
None
attribute model_kwargs: Optional[dict] = None
Key word arguments to pass to the model. Reserved for future use
attribute tags: Optional[List[str]] = None
Tags to add to the run trace.
attribute verbose: bool [Optional]
Whether to print out response text.
__call__(prompt, stop=None, callbacks=None, **kwargs)
Check Cache and run the LLM on the given prompt and input.
Parameters
prompt (str) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
str


kwargs (Any) –
Return type
str
async agenerate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async agenerate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async apredict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
async apredict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
classmethod construct(_fields_set=None, **values)
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.


Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
Parameters
_fields_set (Optional[SetStr]) –
values (Any) –
Return type
Model
copy(*, include=None, exclude=None, update=None, deep=False)
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
Returns
new model instance
Return type
Model
dict(**kwargs)
Return a dictionary of the LLM.
Parameters
kwargs (Any) –
Return type
Dict
generate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
generate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters


Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
get_num_tokens(text)
Get the number of tokens present in the text.
Parameters
text (str) –
Return type
int
get_num_tokens_from_messages(messages)
Get the number of tokens in the message.
Parameters
messages (List[langchain.schema.BaseMessage]) –
Return type
int
get_token_ids(text)
Get the token present in the text.
Parameters
text (str) –
Return type
List[int]
json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
by_alias (bool) –
skip_defaults (Optional[bool]) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Optional[Callable[[Any], Any]]) –
models_as_dict (bool) –
dumps_kwargs (Any) –
Return type
unicode


dumps_kwargs (Any) –
Return type
unicode
predict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
predict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
save(file_path)
Save the LLM.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the LLM to.
Return type
None
Example:
.. code-block:: python
llm.save(file_path=”path/llm.yaml”)
classmethod update_forward_refs(**localns)
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) –
Return type
None
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.


property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.llms.Aviary(*, cache=None, verbose=None, callbacks=None, callback_manager=None, tags=None, model='amazon/LightGPT', aviary_url=None, aviary_token=None, use_prompt_format=True, version=None)[source]
Bases: langchain.llms.base.LLM
Allow you to use an Aviary.
Aviary is a backend for hosted models. You can
find out more about aviary at
http://github.com/ray-project/aviary
To get a list of the models supported on an
aviary, follow the instructions on the web site to
install the aviary CLI and then use:
aviary models
AVIARY_URL and AVIARY_TOKEN environement variables must be set.
Example
from langchain.llms import Aviary
os.environ["AVIARY_URL"] = "<URL>"
os.environ["AVIARY_TOKEN"] = "<TOKEN>"
light = Aviary(model='amazon/LightGPT')
output = light('How do you make fried rice?')
Parameters
cache (Optional[bool]) –
verbose (bool) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
tags (Optional[List[str]]) –
model (str) –
aviary_url (Optional[str]) –
aviary_token (Optional[str]) –
use_prompt_format (bool) –
version (Optional[str]) –
Return type
None
attribute tags: Optional[List[str]] = None
Tags to add to the run trace.
attribute verbose: bool [Optional]


Tags to add to the run trace.
attribute verbose: bool [Optional]
Whether to print out response text.
__call__(prompt, stop=None, callbacks=None, **kwargs)
Check Cache and run the LLM on the given prompt and input.
Parameters
prompt (str) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
str
async agenerate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async agenerate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async apredict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
async apredict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters


Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
classmethod construct(_fields_set=None, **values)
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
Parameters
_fields_set (Optional[SetStr]) –
values (Any) –
Return type
Model
copy(*, include=None, exclude=None, update=None, deep=False)
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
Returns
new model instance
Return type
Model
dict(**kwargs)
Return a dictionary of the LLM.
Parameters
kwargs (Any) –
Return type
Dict
generate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –


Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
generate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
get_num_tokens(text)
Get the number of tokens present in the text.
Parameters
text (str) –
Return type
int
get_num_tokens_from_messages(messages)
Get the number of tokens in the message.
Parameters
messages (List[langchain.schema.BaseMessage]) –
Return type
int
get_token_ids(text)
Get the token present in the text.
Parameters
text (str) –
Return type
List[int]
json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –


include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
by_alias (bool) –
skip_defaults (Optional[bool]) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Optional[Callable[[Any], Any]]) –
models_as_dict (bool) –
dumps_kwargs (Any) –
Return type
unicode
predict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
predict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
save(file_path)
Save the LLM.
Parameters
file_path (Union[pathlib.Path, str]) – Path to file to save the LLM to.
Return type
None
Example:
.. code-block:: python
llm.save(file_path=”path/llm.yaml”)
classmethod update_forward_refs(**localns)
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) –
Return type
None
property lc_attributes: Dict
Return a list of attribute names that should be included in the
serialized kwargs. These attributes must be accepted by the
constructor.
property lc_namespace: List[str]
Return the namespace of the langchain object.


property lc_namespace: List[str]
Return the namespace of the langchain object.
eg. [“langchain”, “llms”, “openai”]
property lc_secrets: Dict[str, str]
Return a map of constructor argument names to secret ids.
eg. {“openai_api_key”: “OPENAI_API_KEY”}
property lc_serializable: bool
Return whether or not the class is serializable.
class langchain.llms.AzureMLOnlineEndpoint(*, cache=None, verbose=None, callbacks=None, callback_manager=None, tags=None, endpoint_url='', endpoint_api_key='', deployment_name='', http_client=None, content_formatter=None, model_kwargs=None)[source]
Bases: langchain.llms.base.LLM, pydantic.main.BaseModel
Wrapper around Azure ML Hosted models using Managed Online Endpoints.
Example
azure_llm = AzureMLModel(
    endpoint_url="https://<your-endpoint>.<your_region>.inference.ml.azure.com/score",
    endpoint_api_key="my-api-key",
    deployment_name="my-deployment-name",
    content_formatter=content_formatter,
)
Parameters
cache (Optional[bool]) –
verbose (bool) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) –
tags (Optional[List[str]]) –
endpoint_url (str) –
endpoint_api_key (str) –
deployment_name (str) –
http_client (Any) –
content_formatter (Any) –
model_kwargs (Optional[dict]) –
Return type
None
attribute content_formatter: Any = None
The content formatter that provides an input and output


attribute content_formatter: Any = None
The content formatter that provides an input and output
transform function to handle formats between the LLM and
the endpoint
attribute deployment_name: str = ''
Deployment Name for Endpoint. Should be passed to constructor or specified as
env var AZUREML_DEPLOYMENT_NAME.
attribute endpoint_api_key: str = ''
Authentication Key for Endpoint. Should be passed to constructor or specified as
env var AZUREML_ENDPOINT_API_KEY.
attribute endpoint_url: str = ''
URL of pre-existing Endpoint. Should be passed to constructor or specified as
env var AZUREML_ENDPOINT_URL.
attribute model_kwargs: Optional[dict] = None
Key word arguments to pass to the model.
attribute tags: Optional[List[str]] = None
Tags to add to the run trace.
attribute verbose: bool [Optional]
Whether to print out response text.
__call__(prompt, stop=None, callbacks=None, **kwargs)
Check Cache and run the LLM on the given prompt and input.
Parameters
prompt (str) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
str
async agenerate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult


kwargs (Any) –
Return type
langchain.schema.LLMResult
async agenerate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
async apredict(text, *, stop=None, **kwargs)
Predict text from text.
Parameters
text (str) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
str
async apredict_messages(messages, *, stop=None, **kwargs)
Predict message from messages.
Parameters
messages (List[langchain.schema.BaseMessage]) –
stop (Optional[Sequence[str]]) –
kwargs (Any) –
Return type
langchain.schema.BaseMessage
classmethod construct(_fields_set=None, **values)
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
Parameters
_fields_set (Optional[SetStr]) –
values (Any) –
Return type
Model
copy(*, include=None, exclude=None, update=None, deep=False)
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model


exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
Returns
new model instance
Return type
Model
dict(**kwargs)
Return a dictionary of the LLM.
Parameters
kwargs (Any) –
Return type
Dict
generate(prompts, stop=None, callbacks=None, *, tags=None, **kwargs)
Run the LLM on the given prompt and input.
Parameters
prompts (List[str]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
tags (Optional[List[str]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
generate_prompt(prompts, stop=None, callbacks=None, **kwargs)
Take in a list of prompt values and return an LLMResult.
Parameters
prompts (List[langchain.schema.PromptValue]) –
stop (Optional[List[str]]) –
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) –
kwargs (Any) –
Return type
langchain.schema.LLMResult
get_num_tokens(text)
Get the number of tokens present in the text.
Parameters
text (str) –
Return type
int
get_num_tokens_from_messages(messages)
Get the number of tokens in the message.
Parameters