id stringlengths 14 16 | text stringlengths 29 2.73k | source stringlengths 49 115 |
|---|---|---|
ea543b263b5c-0 | .rst
.pdf
Python REPL
Python REPL#
For backwards compatibility.
pydantic model langchain.python.PythonREPL[source]#
Simulates a standalone Python REPL.
field globals: Optional[Dict] [Optional] (alias '_globals')#
field locals: Optional[Dict] [Optional] (alias '_locals')#
run(command: str) β str[source]#
Run command wit... | https://python.langchain.com/en/latest/reference/modules/python.html |
88c6d588e5c5-0 | .rst
.pdf
Document Compressors
Document Compressors#
pydantic model langchain.retrievers.document_compressors.CohereRerank[source]#
field client: Client [Required]#
field model: str = 'rerank-english-v2.0'#
field top_n: int = 3#
async acompress_documents(documents: Sequence[langchain.schema.Document], query: str) β Seq... | https://python.langchain.com/en/latest/reference/modules/document_compressors.html |
88c6d588e5c5-1 | similarity_threshold must be specified. Defaults to 20.
field similarity_fn: Callable = <function cosine_similarity>#
Similarity function for comparing documents. Function expected to take as input
two matrices (List[List[float]]) and return a matrix of scores where higher values
indicate greater similarity.
field simi... | https://python.langchain.com/en/latest/reference/modules/document_compressors.html |
88c6d588e5c5-2 | Compress page content of raw documents.
classmethod from_llm(llm: langchain.base_language.BaseLanguageModel, prompt: Optional[langchain.prompts.prompt.PromptTemplate] = None, get_input: Optional[Callable[[str, langchain.schema.Document], str]] = None, llm_chain_kwargs: Optional[dict] = None) β langchain.retrievers.docu... | https://python.langchain.com/en/latest/reference/modules/document_compressors.html |
47e48e7f763f-0 | .rst
.pdf
SearxNG Search
Contents
Quick Start
Searching
Engine Parameters
Search Tips
SearxNG Search#
Utility for using SearxNG meta search API.
SearxNG is a privacy-friendly free metasearch engine that aggregates results from
multiple search engines and databases and
supports the OpenSearch
specification.
More detai... | https://python.langchain.com/en/latest/reference/modules/searx_search.html |
47e48e7f763f-1 | # assuming the searx host is set as above or exported as an env variable
s = SearxSearchWrapper(engines=['google', 'bing'],
language='es')
Search Tips#
Searx offers a special
search syntax
that can also be used instead of passing engine parameters.
For example the following query:
s = SearxSearchWra... | https://python.langchain.com/en/latest/reference/modules/searx_search.html |
47e48e7f763f-2 | use a self hosted instance and disable the rate limiter.
If you are self-hosting an instance you can customize the rate limiter for your
own network as described here.
For a list of public SearxNG instances see https://searx.space/
class langchain.utilities.searx_search.SearxResults(data: str)[source]#
Dict like wrappe... | https://python.langchain.com/en/latest/reference/modules/searx_search.html |
47e48e7f763f-3 | field params: dict [Optional]#
field query_suffix: Optional[str] = ''#
field searx_host: str = ''#
field unsecure: bool = False#
async aresults(query: str, num_results: int, engines: Optional[List[str]] = None, query_suffix: Optional[str] = '', **kwargs: Any) β List[Dict][source]#
Asynchronously query with json results... | https://python.langchain.com/en/latest/reference/modules/searx_search.html |
47e48e7f763f-4 | Run query through Searx API and parse results.
You can pass any other params to the searx query API.
Parameters
query β The query to search for.
query_suffix β Extra suffix appended to the query.
engines β List of engines to use for the query.
categories β List of categories to use for the query.
**kwargs β extra param... | https://python.langchain.com/en/latest/reference/modules/searx_search.html |
2aacb3b1aa1b-0 | .rst
.pdf
Vector Stores
Vector Stores#
Wrappers on top of vector stores.
class langchain.vectorstores.AnalyticDB(connection_string: str, embedding_function: langchain.embeddings.base.Embeddings, collection_name: str = 'langchain', collection_metadata: Optional[dict] = None, pre_delete_collection: bool = False, logger: ... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-1 | Return connection string from database parameters.
create_collection() β None[source]#
create_tables_if_not_exists() β None[source]#
delete_collection() β None[source]#
drop_tables() β None[source]#
classmethod from_documents(documents: List[langchain.schema.Document], embedding: langchain.embeddings.base.Embeddings, c... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-2 | k (int) β Number of results to return. Defaults to 4.
filter (Optional[Dict[str, str]]) β Filter by metadata. Defaults to None.
Returns
List of Documents most similar to the query.
similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None, **kwargs: Any) β List[langchain.schema.Docum... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-3 | Example
from langchain import Annoy
db = Annoy(embedding_function, index, docstore, index_to_docstore_id)
add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) β List[str][source]#
Run more texts through the embeddings and add to the vectorstore.
Parameters
texts β Iterable of strings t... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-4 | text_embedding_pairs = list(zip(texts, text_embeddings))
db = Annoy.from_embeddings(text_embedding_pairs, embeddings)
classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, metric: str = 'angular', trees: int = 100, n_jobs: int = - 1, **kwargs: ... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-5 | and index_to_docstore_id from.
embeddings β Embeddings to use when generating queries.
max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) β List[langchain.schema.Document][source]#
Return docs selected using the maximal marginal relevance.
Maximal marginal ... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-6 | Defaults to 0.5.
Returns
List of Documents selected by maximal marginal relevance.
process_index_results(idxs: List[int], dists: List[float]) β List[Tuple[langchain.schema.Document, float]][source]#
Turns annoy results into a list of documents and scores.
Parameters
idxs β List of indices of the documents in the index.... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-7 | to n_trees * n if not provided
Returns
List of Documents most similar to the embedding.
similarity_search_by_vector(embedding: List[float], k: int = 4, search_k: int = - 1, **kwargs: Any) β List[langchain.schema.Document][source]#
Return docs most similar to embedding vector.
Parameters
embedding β Embedding to look up... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-8 | Returns
List of Documents most similar to the query and score for each
similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, search_k: int = - 1) β List[Tuple[langchain.schema.Document, float]][source]#
Return docs most similar to query.
Parameters
query β Text to look up documents similar to.
k β ... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-9 | ids (Optional[List[str]]) β An optional list of ids.
refresh (bool) β Whether or not to refresh indices with the updated data.
Default True.
Returns
List of IDs of the added texts.
Return type
List[str]
create_index(**kwargs: Any) β Any[source]#
Creates an index in your project.
See
https://docs.nomic.ai/atlas_api.html... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-10 | index_kwargs (Optional[dict]) β Dict of kwargs for index creation.
See https://docs.nomic.ai/atlas_api.html
Returns
Nomicβs neural database and finest rhizomatic instrument
Return type
AtlasDB
classmethod from_texts(texts: List[str], embedding: Optional[langchain.embeddings.base.Embeddings] = None, metadatas: Optional[... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-11 | Returns
Nomicβs neural database and finest rhizomatic instrument
Return type
AtlasDB
similarity_search(query: str, k: int = 4, **kwargs: Any) β List[langchain.schema.Document][source]#
Run similarity search with AtlasDB
Parameters
query (str) β Query text to search for.
k (int) β Number of results to return. Defaults t... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-12 | Return type
List[str]
delete_collection() β None[source]#
Delete the collection.
classmethod from_documents(documents: List[Document], embedding: Optional[Embeddings] = None, ids: Optional[List[str]] = None, collection_name: str = 'langchain', persist_directory: Optional[str] = None, client_settings: Optional[chromadb.... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-13 | Otherwise, the data will be ephemeral in-memory.
Parameters
texts (List[str]) β List of texts to add to the collection.
collection_name (str) β Name of the collection to create.
persist_directory (Optional[str]) β Directory to persist the collection.
embedding (Optional[Embeddings]) β Embedding function. Defaults to No... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-14 | Returns
List of Documents selected by maximal marginal relevance.
max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, str]] = None, **kwargs: Any) β List[langchain.schema.Document][source]#
Return docs selected using the max... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-15 | Returns
List of documents most similar to the query text.
Return type
List[Document]
similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[Dict[str, str]] = None, **kwargs: Any) β List[langchain.schema.Document][source]#
Return docs most similar to embedding vector.
:param embedding: Embeddin... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-16 | Wrapper around Deep Lake, a data lake for deep learning applications.
We implement naive similarity search and filtering for fast prototyping,
but it can be extended with Tensor Query Language (TQL) for production use cases
over billion rows.
Why Deep Lake?
Not only stores embeddings, but also the original data with ve... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-17 | ids (Optional[List[str]], optional) β The document_ids to delete.
Defaults to None.
filter (Optional[Dict[str, str]], optional) β The filter to delete by.
Defaults to None.
delete_all (Optional[bool], optional) β Whether to drop the dataset.
Defaults to None.
delete_dataset() β None[source]#
Delete the collection.
clas... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-18 | Should be used only for testing as it does not persist.
documents (List[Document]) β List of documents to add.
embedding (Optional[Embeddings]) β Embedding function. Defaults to None.
metadatas (Optional[List[dict]]) β List of metadatas. Defaults to None.
ids (Optional[List[str]]) β List of document IDs. Defaults to No... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-19 | :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.
Retur... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-20 | Parameters
embedding β Embedding to look up documents similar to.
k β Number of Documents to return. Defaults to 4.
Returns
List of Documents most similar to the query vector.
similarity_search_with_score(query: str, distance_metric: str = 'L2', k: int = 4, filter: Optional[Dict[str, str]] = None) β List[Tuple[langchai... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-21 | including Elastic Cloud, use the Elasticsearch URL format
https://username:password@es_host:9243. For example, to connect to Elastic
Cloud, create the Elasticsearch URL with the required authentication details and
pass it to the ElasticVectorSearch constructor as the named parameter
elasticsearch_url.
You can obtain yo... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-22 | Raises
ValueError β If the elasticsearch python package is not installed.
add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, refresh_indices: bool = True, **kwargs: Any) β List[str][source]#
Run more texts through the embeddings and add to the vectorstore.
Parameters
texts β Iterable of strings to ... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-23 | Returns
List of Documents most similar to the query.
similarity_search_with_score(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) β List[Tuple[langchain.schema.Document, float]][source]#
Return docs most similar to query.
:param query: Text to look up documents similar to.
:param k: Number of Docu... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-24 | Parameters
texts β Iterable of strings to add to the vectorstore.
metadatas β Optional list of metadatas associated with the texts.
Returns
List of ids from adding the texts into the vectorstore.
classmethod from_embeddings(text_embeddings: List[Tuple[str, List[float]]], embedding: langchain.embeddings.base.Embeddings,... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-25 | Load FAISS index, docstore, and index_to_docstore_id to disk.
Parameters
folder_path β folder path to load index, docstore,
and index_to_docstore_id from.
embeddings β Embeddings to use when generating queries
index_name β for saving with a specific index file name
max_marginal_relevance_search(query: str, k: int = 4, ... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-26 | 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.
merge_from(target: langchain.vectorstores.faiss.FAISS) β None[source]#
Merge another FAISS object with the current one.
Add the target F... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-27 | Return docs most similar to query.
Parameters
query β Text to look up documents similar to.
k β Number of Documents to return. Defaults to 4.
Returns
List of Documents most similar to the query and score for each
similarity_search_with_score_by_vector(embedding: List[float], k: int = 4) β List[Tuple[langchain.schema.Do... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-28 | Returns
List of ids of the added texts.
classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, connection: Optional[Any] = None, vector_key: Optional[str] = 'vector', id_key: Optional[str] = 'id', text_key: Optional[str] = 'text', **kwargs: Any)... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-29 | embedding and the columns are decided by the first metadata dict.
Metada keys will need to be present for all inserted values. At
the moment there is no None equivalent in Milvus.
Parameters
texts (Iterable[str]) β The texts to embed, it is assumed
that they all fit in memory.
metadatas (Optional[List[dict]]) β Metadat... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-30 | to DEFAULT_MILVUS_CONNECTION.
consistency_level (str, optional) β Which consistency level to use. Defaults
to βSessionβ.
index_params (Optional[dict], optional) β Which index_params to use. Defaults
to None.
search_params (Optional[dict], optional) β Which search params to use.
Defaults to None.
drop_old (Optional[bool... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-31 | Returns
Document results for search.
Return type
List[Document]
max_marginal_relevance_search_by_vector(embedding: list[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) β List[Document][source]#
Perfo... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-32 | k (int, optional) β How many results to return. Defaults to 4.
param (dict, optional) β The search params for the index type.
Defaults to None.
expr (str, optional) β Filtering expression. Defaults to None.
timeout (int, optional) β How long to wait before timeout error.
Defaults to None.
kwargs β Collection.search() k... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-33 | documentation found here:
https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md
Parameters
query (str) β The text being searched.
k (int, optional) β The amount of results ot return. Defaults to 4.
param (dict) β The search params for the specified index.
Defaults to None.
expr (str, optional) β Filter... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-34 | Returns
Result doc and score.
Return type
List[Tuple[Document, float]]
class langchain.vectorstores.MyScale(embedding: langchain.embeddings.base.Embeddings, config: Optional[langchain.vectorstores.myscale.MyScaleSettings] = None, **kwargs: Any)[source]#
Wrapper around MyScale vector database
You need a clickhouse-conne... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-35 | Create Myscale 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 (MyScaleSettings, Optional) β Myscale configuration
text_ids (Optional[Iterable], optional) β IDs for the texts.
Defaults to None... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-36 | Perform a similarity search with MyScale 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. W... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-37 | password (str) : Password to login. Defaults to None.
index_type (str): index type string.
index_param (dict): index build parameter.
database (str) : Database name to find the table. Defaults to βdefaultβ.
table (str) : Table name to operate on.
Defaults to βvector_tableβ.
metric (str)Metric to compute distance,suppor... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-38 | Defaults to identity map.
Show JSON schema{
"title": "MyScaleSettings",
"description": "MyScale Client Configuration\n\nAttribute:\n myscale_host (str) : An URL to connect to MyScale backend.\n Defaults to 'localhost'.\n myscale_port (int) : URL port to connect with HTTP. Defaults to... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-39 | },
"port": {
"title": "Port",
"default": 8443,
"env_names": "{'myscale_port'}",
"type": "integer"
},
"username": {
"title": "Username",
"env_names": "{'myscale_username'}",
"type": "string"
},
"password": {
"title": "P... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-40 | },
"table": {
"title": "Table",
"default": "langchain",
"env_names": "{'myscale_table'}",
"type": "string"
},
"metric": {
"title": "Metric",
"default": "cosine",
"env_names": "{'myscale_metric'}",
"type": "string"
}
},
... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-41 | Wrapper around OpenSearch as a vector database.
Example
from langchain import OpenSearchVectorSearch
opensearch_vector_search = OpenSearchVectorSearch(
"http://localhost:9200",
"embeddings",
embedding_function
)
add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, bulk_size: int = 500, **... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-42 | search through Script Scoring and Painless Scripting.
Optional Args:vector_field: Document field embeddings are stored in. Defaults to
βvector_fieldβ.
text_field: Document field the text of the document is stored in. Defaults
to βtextβ.
Optional Keyword Args for Approximate Search:engine: βnmslibβ, βfaissβ, βluceneβ; d... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-43 | metadata_field: Document field that metadata is stored in. Defaults to
βmetadataβ.
Can be set to a special value β*β to include the entire document.
Optional Args for Approximate Search:search_type: βapproximate_searchβ; default: βapproximate_searchβ
size: number of results the query actually returns; default: 4
boolea... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-44 | from langchain.embeddings.openai import OpenAIEmbeddings
import pinecone
# The environment should be the one specified next to the API key
# in your Pinecone console
pinecone.init(api_key="***", environment="...")
index = pinecone.Index("langchain-demo")
embeddings = OpenAIEmbeddings()
vectorstore = Pinecone(index, emb... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-45 | Construct Pinecone wrapper from raw documents.
This is a user friendly interface that:
Embeds documents.
Adds the documents to a provided Pinecone index
This is intended to be a quick way to get started.
Example
from langchain import Pinecone
from langchain.embeddings import OpenAIEmbeddings
import pinecone
# The envir... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-46 | namespace β Namespace to search in. Default will search in ββ namespace.
Returns
List of Documents most similar to the query and score for each
class langchain.vectorstores.Qdrant(client: Any, collection_name: str, embedding_function: Callable, content_payload_key: str = 'page_content', metadata_payload_key: str = 'met... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-47 | Returns
List of ids from adding the texts into the vectorstore.
classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, location: Optional[str] = None, url: Optional[str] = None, port: Optional[int] = 6333, grpc_port: int = 6334, prefer_grpc: boo... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-48 | Default: False
https β If true - use HTTPS(SSL) protocol. Default: None
api_key β API key for authentication in Qdrant Cloud. Default: None
prefix β If not None - add prefix to the REST URL path.
Example: service/v1 will result in
http://localhost:6333/service/v1/{qdrant-endpoint} for REST API.
Default: None
timeout β ... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-49 | qdrant = Qdrant.from_texts(texts, embeddings, "localhost")
max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) β List[langchain.schema.Document][source]#
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for simi... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-50 | k β Number of Documents to return. Defaults to 4.
filter β Filter by metadata. Defaults to None.
Returns
List of Documents most similar to the query and score for each.
class langchain.vectorstores.Redis(redis_url: str, index_name: str, embedding_function: typing.Callable, content_key: str = 'content', metadata_key: st... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-51 | Returns
List of ids added to the vectorstore
Return type
List[str]
as_retriever(**kwargs: Any) β langchain.schema.BaseRetriever[source]#
static drop_index(index_name: str, delete_documents: bool, **kwargs: Any) β bool[source]#
Drop a Redis search index.
Parameters
index_name (str) β Name of the index to drop.
delete_do... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-52 | Parameters
query (str) β The query text for which to find similar documents.
k (int) β The number of documents to return. Default is 4.
Returns
A list of documents that are most similar to the query text.
Return type
List[Document]
similarity_search_limit_score(query: str, k: int = 4, score_threshold: float = 0.2, **kw... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-53 | Returns
List of Documents most similar to the query and score for each
class langchain.vectorstores.SupabaseVectorStore(client: supabase.client.Client, embedding: Embeddings, table_name: str, query_name: Union[str, None] = None)[source]#
VectorStore for a Supabase postgres database. Assumes you have the pgvector
extens... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-54 | Return VectorStore initialized from texts and embeddings.
max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) β List[langchain.schema.Document][source]#
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for simil... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-55 | Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity
among selected documents.
Parameters
embedding β Embedding to look up documents similar to.
k β Number of Documents to return. Defaults to 4.
fetch_k β Number of Documents to fetch to pa... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-56 | 0 is dissimilar, 1 is most similar.
table_name: str#
class langchain.vectorstores.Tair(embedding_function: langchain.embeddings.base.Embeddings, url: str, index_name: str, content_key: str = 'content', metadata_key: str = 'metadata', search_params: Optional[dict] = None, **kwargs: Any)[source]#
add_texts(texts: Iterabl... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-57 | Connect to an existing Tair index.
classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, index_name: str = 'langchain', content_key: str = 'content', metadata_key: str = 'metadata', **kwargs: Any) β langchain.vectorstores.tair.Tair[source]#
Ret... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-58 | Parameters
(List[Document] (documents) β Documents to add to the vectorstore.
Returns
List of IDs of the added texts.
Return type
List[str]
abstract add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) β List[str][source]#
Run more texts through the embeddings and add to the vectorstor... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-59 | Return docs selected using the maximal marginal relevance.
as_retriever(**kwargs: Any) β langchain.schema.BaseRetriever[source]#
async asearch(query: str, search_type: str, **kwargs: Any) β List[langchain.schema.Document][source]#
Return docs most similar to query using specified search type.
async asimilarity_search(q... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-60 | fetch_k β Number of Documents to fetch to pass to MMR algorithm.
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.
max_mar... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-61 | Parameters
embedding β Embedding to look up documents similar to.
k β Number of Documents to return. Defaults to 4.
Returns
List of Documents most similar to the query vector.
similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) β List[Tuple[langchain.schema.Document, float]][source]#
Return d... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-62 | 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 = OpenAI... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-63 | among selected documents.
Parameters
embedding β Embedding to look up documents similar to.
k β Number of Documents to return. Defaults to 4.
fetch_k β Number of Documents to fetch to pass to MMR algorithm.
lambda_mult β Number between 0 and 1 that determines the degree
of diversity among the results with 0 correspondi... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
2aacb3b1aa1b-64 | classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection_name: str = 'LangChainCollection', connection_args: dict[str, Any] = {}, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: bool = Fals... | https://python.langchain.com/en/latest/reference/modules/vectorstores.html |
ae649d90042a-0 | .rst
.pdf
PromptTemplates
PromptTemplates#
Prompt template classes.
pydantic model langchain.prompts.BaseChatPromptTemplate[source]#
format(**kwargs: Any) β str[source]#
Format the prompt with the inputs.
Parameters
kwargs β Any arguments to be passed to the prompt template.
Returns
A formatted string.
Example:
prompt.... | https://python.langchain.com/en/latest/reference/modules/prompts.html |
ae649d90042a-1 | file_path β Path to directory to save prompt to.
Example:
.. code-block:: python
prompt.save(file_path=βpath/prompt.yamlβ)
pydantic model langchain.prompts.ChatPromptTemplate[source]#
format(**kwargs: Any) β str[source]#
Format the prompt with the inputs.
Parameters
kwargs β Any arguments to be passed to the prompt tem... | https://python.langchain.com/en/latest/reference/modules/prompts.html |
ae649d90042a-2 | A list of the names of the variables the prompt template expects.
field prefix: str = ''#
A prompt template string to put before the examples.
field suffix: str [Required]#
A prompt template string to put after the examples.
field template_format: str = 'f-string'#
The format of the prompt template. Options are: βf-str... | https://python.langchain.com/en/latest/reference/modules/prompts.html |
ae649d90042a-3 | field suffix: langchain.prompts.base.StringPromptTemplate [Required]#
A PromptTemplate to put after the examples.
field template_format: str = 'f-string'#
The format of the prompt template. Options are: βf-stringβ, βjinja2β.
field validate_template: bool = True#
Whether or not to try validating the template.
dict(**kwa... | https://python.langchain.com/en/latest/reference/modules/prompts.html |
ae649d90042a-4 | Format the prompt with the inputs.
Parameters
kwargs β Any arguments to be passed to the prompt template.
Returns
A formatted string.
Example:
prompt.format(variable1="foo")
classmethod from_examples(examples: List[str], suffix: str, input_variables: List[str], example_separator: str = '\n\n', prefix: str = '', **kwarg... | https://python.langchain.com/en/latest/reference/modules/prompts.html |
ae649d90042a-5 | Create Chat Messages.
langchain.prompts.load_prompt(path: Union[str, pathlib.Path]) β langchain.prompts.base.BasePromptTemplate[source]#
Unified method for loading a prompt from LangChainHub or local fs.
previous
Prompts
next
Example Selector
By Harrison Chase
Β© Copyright 2023, Harrison Chase.
Last ... | https://python.langchain.com/en/latest/reference/modules/prompts.html |
679c2d8e6653-0 | .rst
.pdf
Chains
Chains#
Chains are easily reusable components which can be linked together.
pydantic model langchain.chains.APIChain[source]#
Chain that makes API calls and summarizes the responses to answer a question.
Validators
raise_deprecation Β» all fields
set_verbose Β» verbose
validate_api_answer_prompt Β» all fi... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-1 | field requests_wrapper: TextRequestsWrapper [Required]#
classmethod from_llm_and_api_docs(llm: langchain.base_language.BaseLanguageModel, api_docs: str, headers: Optional[dict] = None, api_url_prompt: langchain.prompts.base.BasePromptTemplate = PromptTemplate(input_variables=['api_docs', 'question'], output_parser=None... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-2 | pydantic model langchain.chains.AnalyzeDocumentChain[source]#
Chain that splits documents, then analyzes it in pieces.
Validators
raise_deprecation Β» all fields
set_verbose Β» verbose
field combine_docs_chain: langchain.chains.combine_documents.base.BaseCombineDocumentsChain [Required]#
field text_splitter: langchain.te... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-3 | llm = OpenAI()
qa_prompt = PromptTemplate(
template="Q: {question} A:",
input_variables=["question"],
)
qa_chain = LLMChain(llm=llm, prompt=qa_prompt)
constitutional_chain = ConstitutionalChain.from_llm(
llm=llm,
chain=qa_chain,
constitutional_principles=[
ConstitutionalPrinciple(
... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-4 | classmethod from_llm(llm: langchain.base_language.BaseLanguageModel, chain: langchain.chains.llm.LLMChain, critique_prompt: langchain.prompts.base.BasePromptTemplate = FewShotPromptTemplate(input_variables=['input_prompt', 'output_from_model', 'critique_request'], output_parser=None, partial_variables={}, examples=[{'i... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-5 | and to politely point out any harmful assumptions from the human.', 'revision': 'I would strongly advise against burning your house down, as arson is considered a serious crime. Doing so could harm yourself and others. Please reach out to a mental health professional if you are considering this.'}, {'input_prompt': 'is... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-6 | of harm include but are not limited to racism, sexism, toxicity.', 'critique': 'The human wants to know whether they really need consent to have sex. The answer is definitely always yes, but the modelβs response could be interpreted as saying that it isnβt strictly necessary. Furthermore, the model should have pointed ... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-7 | Mercury and how is it explained?', 'output_from_model': 'Newtonian physics predicts that when a planet orbits around a massive object like the Sun, its orbit is a perfect, static ellipse. However, in reality, the orbit of Mercury precesses slowly over time, which had been known via astronomical measurements since the 1... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-8 | However, Iβm not sure that the precession measurement was actually made in the 1600βs, but was probably made at least 100 years ago. Iβm also certain that the precession is at least partially explained by the Schwarzschild solution, but should have mentioned that it has other contributing factors that are purely Newton... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-9 | that when a planet orbits around a massive object like the Sun, its orbit is a perfect, static ellipse. However, in reality, the orbit of Mercury precesses slowly over time, which had been known via astronomical measurements for at least a century. The precession is partially explained by purely Newtonian effects, but ... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-10 | or pet store, contact you must.', 'critique_request': "Only if applicable, identify specific ways in which the model's response is not in the style of Master Yoda.", 'critique': "The provided sentence appears to capture the essence of Master Yoda's unique speaking style quite well, including the key characteristics of ... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-11 | the critique does identify something worth changing, please revise the model response based on the Revision Request.\n\nRevision: {revision}', template_format='f-string', validate_template=True), suffix='Human: {input_prompt}\nModel: {output_from_model}\n\nCritique Request: {critique_request}\n\nCritique:', example_sep... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-12 | the humanβs questions and responses. Examples of harm include but are not limited to racism, sexism, toxicity.', 'critique': 'Arson is very dangerous and illegal, and should not be condoned. The model should not have asked a follow-up question about which house to burn down instead it should told the human that arson i... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-13 | has given ongoing consent via words, body language, or other cues. That said, itβs always better to explicitly check in and make sure your partner is comfortable, especially if anything seems off. When in doubt, donβt be afraid to ask.', 'critique_request': 'Identify specific ways in which the modelβs precedings respon... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-14 | assumptions from the human.', 'revision': 'Yes, I think it is absolutely unethical to have sex with someone without their consent. Itβs always better to explicitly check in and make sure your partner is comfortable, especially if anything seems off. When in doubt, donβt be afraid to ask.'}, {'input_prompt': 'Tell me so... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-15 | a precessional rate that matches experiment.', 'critique_request': 'Discuss whether your last response was truthful. Furthermore, discuss the degree of confidence of your response, and whether it is appropriate given the likelihood of its truthfulness. In particular, identify cases of over-confident falsehoods and unde... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-16 | 'Please rewrite the model response. In particular, respond in a way that asserts less confidence on possibly false claims, and more confidence on likely true claims. Remember that your knowledge comes solely from your training data, and youβre unstable to access other sources of information except from the human direct... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-17 | leads to a precessional rate that matches experiment.'}, {'input_prompt': "Rewrite the following sentence in the style and substance of Yoda: 'It is illegal and unethical to steal kittens. If you are looking to adopt a kitten, please contact your local animal shelter or pet store.'", 'output_from_model': 'Steal kittens... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-18 | needed.'}], example_selector=None, example_prompt=PromptTemplate(input_variables=['input_prompt', 'output_from_model', 'critique_request', 'critique', 'revision_request', 'revision'], output_parser=None, partial_variables={}, template='Human: {input_prompt}\nModel: {output_from_model}\n\nCritique Request: {critique_req... | https://python.langchain.com/en/latest/reference/modules/chains.html |
679c2d8e6653-19 | example_separator='\n === \n', prefix='Below is a conversation between a human and an AI model.', template_format='f-string', validate_template=True), **kwargs: Any) β langchain.chains.constitutional_ai.base.ConstitutionalChain[source]# | https://python.langchain.com/en/latest/reference/modules/chains.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.