Tony20100/langchain_full huggingface dataset:
langchain_community.retrievers.knn.KNNRetriever¶
class langchain_community.retrievers.knn.KNNRetriever[source]¶
Bases: BaseRetriever
KNN retriever.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param embeddings: Embeddings [Required]¶
Embeddings model to use.
param index: Any = None¶
Index of embeddings.
param k: int = 4¶
Number of results to return.
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the retriever. Defaults to None
This metadata will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a retriever with its
use case.
param metadatas: Optional[List[dict]] = None¶
List of metadatas corresponding with each text.
param relevancy_threshold: Optional[float] = None¶
Threshold for relevancy.
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the retriever. Defaults to None
These tags will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a retriever with its
use case.
param texts: List[str] [Required]¶
List of texts to index.
async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶
Default implementation runs ainvoke in parallel using asyncio.gather.
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(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) → DictStrAny¶
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
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) – 
Return type
DictStrAny
classmethod from_documents(documents: Iterable[Document], embeddings: Embeddings, **kwargs: Any) → KNNRetriever[source]¶
Parameters
documents (Iterable[Document]) – 
embeddings (Embeddings) – 
kwargs (Any) – 
Return type
KNNRetriever
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
classmethod from_texts(texts: List[str], embeddings: Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → KNNRetriever[source]¶
Parameters
Parameters
texts (List[str]) – 
embeddings (Embeddings) – 
metadatas (Optional[List[dict]]) – 
kwargs (Any) – 
Return type
KNNRetriever
get_graph(config: Optional[RunnableConfig] = None) → Graph¶
Return a graph representation of this runnable.
Parameters
config (Optional[RunnableConfig]) – 
Return type
Graph
get_input_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate input to the runnable.
Runnables that leverage the configurable_fields and configurable_alternatives
methods will have a dynamic input schema that depends on which
configuration the runnable is invoked with.
This method allows to get an input schema for a specific configuration.
Parameters
config (Optional[RunnableConfig]) – A config to use when generating the schema.
Returns
A pydantic model that can be used to validate input.
Return type
Type[BaseModel]
classmethod get_lc_namespace() → List[str]¶
Get the namespace of the langchain object.
For example, if the class is langchain.llms.openai.OpenAI, then the
namespace is [“langchain”, “llms”, “openai”]
Return type
List[str]
get_name(suffix: Optional[str] = None, *, name: Optional[str] = None) → str¶
Get the name of the runnable.
Parameters
suffix (Optional[str]) – 
name (Optional[str]) – 
Return type
str
get_output_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate output to the runnable.
Runnables that leverage the configurable_fields and configurable_alternatives
property lc_secrets: Dict[str, str]¶
A map of constructor argument names to secret ids.
For example,{“openai_api_key”: “OPENAI_API_KEY”}
name: Optional[str] = None¶
The name of the runnable. Used for debugging and tracing.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
Examples using KNNRetriever¶
Voyage AI
kNN
langchain_community.retrievers.google_vertex_ai_search.GoogleCloudEnterpriseSearchRetriever¶
class langchain_community.retrievers.google_vertex_ai_search.GoogleCloudEnterpriseSearchRetriever[source]¶
Bases: GoogleVertexAISearchRetriever
Google Vertex Search API retriever alias for backwards compatibility.
DEPRECATED: Use GoogleVertexAISearchRetriever instead.
Initializes private fields.
param credentials: Any = None¶
The default custom credentials (google.auth.credentials.Credentials) to use
when making API calls. If not provided, credentials will be ascertained from
the environment.
param data_store_id: Optional[str] = None¶
Vertex AI Search data store ID.
param engine_data_type: int = 0¶
Defines the Vertex AI Search app data type
0 - Unstructured data
1 - Structured data
2 - Website data
3 - Blended search
Constraints
minimum = 0
maximum = 3
param filter: Optional[str] = None¶
Filter expression.
param get_extractive_answers: bool = False¶
If True return Extractive Answers, otherwise return Extractive Segments or Snippets.
param location_id: str = 'global'¶
Vertex AI Search data store location.
param max_documents: int = 5¶
The maximum number of documents to return.
Constraints
minimum = 1
maximum = 100
param max_extractive_answer_count: int = 1¶
The maximum number of extractive answers returned in each search result.
At most 5 answers will be returned for each SearchResult.
Constraints
minimum = 1
maximum = 5
param max_extractive_segment_count: int = 1¶
The maximum number of extractive segments returned in each search result.
Currently one segment will be returned for each SearchResult.
Constraints
minimum = 1
maximum = 1
Constraints
minimum = 1
maximum = 1
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the retriever. Defaults to None
This metadata will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a retriever with its
use case.
param project_id: str [Required]¶
Google Cloud Project ID.
param query_expansion_condition: int = 1¶
Specification to determine under which conditions query expansion should occur.
0 - Unspecified query expansion condition. In this case, server behavior defaults
to disabled
1 - Disabled query expansion. Only the exact search query is used, even ifSearchResponse.total_size is zero.
2 - Automatic query expansion built by the Search API.
Constraints
minimum = 0
maximum = 2
param search_engine_id: Optional[str] = None¶
Vertex AI Search app ID.
param serving_config_id: str = 'default_config'¶
Vertex AI Search serving config ID.
param spell_correction_mode: int = 2¶
Specification to determine under which conditions query expansion should occur.
0 - Unspecified spell correction mode. In this case, server behavior defaults
to auto.
1 - Suggestion only. Search API will try to find a spell suggestion if there is anyand put in the SearchResponse.corrected_query.
The spell suggestion will not be used as the search query.
2 - Automatic spell correction built by the Search API.Search will be based on the corrected query if found.
Constraints
minimum = 0
maximum = 2
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the retriever. Defaults to None
These tags will be associated with each call to this retriever,
config (Optional[RunnableConfig]) – 
Return type
List[BasePromptTemplate]
get_relevant_documents(query: str, *, callbacks: Callbacks = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, **kwargs: Any) → List[Document]¶
[Deprecated] Retrieve documents relevant to a query.
Users should favor using .invoke or .batch rather than
get_relevant_documents directly.
Parameters
query (str) – string to find relevant documents for
callbacks (Callbacks) – Callback manager or list of callbacks
tags (Optional[List[str]]) – Optional list of tags associated with the retriever. Defaults to None
These tags will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
metadata (Optional[Dict[str, Any]]) – Optional metadata associated with the retriever. Defaults to None
This metadata will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
run_name (Optional[str]) – Optional name for the run.
kwargs (Any) – 
Returns
List of relevant documents
Return type
List[Document]
Notes
Deprecated since version langchain-core==0.1.46: Use invoke instead.
get_relevant_documents_with_response(query: str) → Tuple[List[Document], Any]¶
Parameters
query (str) – 
Return type
Tuple[List[Document], Any]
invoke(input: str, config: Optional[RunnableConfig] = None, **kwargs: Any) → List[Document]¶
Invoke the retriever to get relevant documents.
Main entry point for synchronous retriever invocations.
Parameters
input (str) – The query string
config (Optional[RunnableConfig]) – Configuration for the retriever
config (Optional[RunnableConfig]) – Configuration for the retriever
**kwargs (Any) – Additional arguments to pass to the retriever
Returns
List of relevant documents
Return type
List[Document]
Examples:
retriever.invoke("query")
classmethod is_lc_serializable() → bool¶
Is this class serializable?
Return type
bool
json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶
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
classmethod lc_id() → List[str]¶
A unique identifier for this class for serialization purposes.
The unique identifier is a list of strings that describes the path
to the object.
Return type
List[str]
stop_after_attempt (int) – The maximum number of attempts to make before giving up
Returns
A new Runnable that retries the original runnable on exceptions.
Return type
Runnable[Input, Output]
with_types(*, input_type: Optional[Type[Input]] = None, output_type: Optional[Type[Output]] = None) → Runnable[Input, Output]¶
Bind input and output types to a Runnable, returning a new Runnable.
Parameters
input_type (Optional[Type[Input]]) – 
output_type (Optional[Type[Output]]) – 
Return type
Runnable[Input, Output]
property InputType: Type[Input]¶
The type of input this runnable accepts specified as a type annotation.
property OutputType: Type[Output]¶
The type of output this runnable produces specified as a type annotation.
property client_options: ClientOptions¶
property config_specs: List[ConfigurableFieldSpec]¶
List configurable fields for this runnable.
property input_schema: Type[BaseModel]¶
The type of input this runnable accepts specified as a pydantic model.
property lc_attributes: Dict¶
List of attribute names that should be included in the serialized kwargs.
These attributes must be accepted by the constructor.
property lc_secrets: Dict[str, str]¶
A map of constructor argument names to secret ids.
For example,{“openai_api_key”: “OPENAI_API_KEY”}
name: Optional[str] = None¶
The name of the runnable. Used for debugging and tracing.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
langchain_community.retrievers.arcee.ArceeRetriever¶
class langchain_community.retrievers.arcee.ArceeRetriever[source]¶
Bases: BaseRetriever
Arcee Domain Adapted Language Models (DALMs) retriever.
To use, set the ARCEE_API_KEY environment variable with your Arcee API key,
or pass arcee_api_key as a named parameter.
Example
from langchain_community.retrievers import ArceeRetriever
retriever = ArceeRetriever(
    model="DALM-PubMed",
    arcee_api_key="ARCEE-API-KEY"
)
documents = retriever.invoke("AI-driven music therapy")
Initializes private fields.
param arcee_api_key: SecretStr [Required]¶
Arcee API Key
Constraints
type = string
writeOnly = True
format = password
param arcee_api_url: str = 'https://api.arcee.ai'¶
Arcee API URL
param arcee_api_version: str = 'v2'¶
Arcee API Version
param arcee_app_url: str = 'https://app.arcee.ai'¶
Arcee App URL
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the retriever. Defaults to None
This metadata will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a retriever with its
use case.
param model: str [Required]¶
Arcee DALM name
param model_kwargs: Optional[Dict[str, Any]] = None¶
Keyword arguments to pass to the model.
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the retriever. Defaults to None
Optional list of tags associated with the retriever. Defaults to None
These tags will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a retriever with its
use case.
async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶
Default implementation runs ainvoke in parallel using asyncio.gather.
The default implementation of batch works well for IO bound runnables.
Subclasses should override this method if they can batch more efficiently;
e.g., if the underlying runnable uses an API which supports a batch mode.
Parameters
inputs (List[Input]) – 
config (Optional[Union[RunnableConfig, List[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
List[Output]
async abatch_as_completed(inputs: Sequence[Input], config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → AsyncIterator[Tuple[int, Union[Output, Exception]]]¶
Run ainvoke in parallel on a list of inputs,
yielding results as they complete.
Parameters
inputs (Sequence[Input]) – 
config (Optional[Union[RunnableConfig, Sequence[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
AsyncIterator[Tuple[int, Union[Output, Exception]]]
Return type
Runnable[Input, Output]
with_types(*, input_type: Optional[Type[Input]] = None, output_type: Optional[Type[Output]] = None) → Runnable[Input, Output]¶
Bind input and output types to a Runnable, returning a new Runnable.
Parameters
input_type (Optional[Type[Input]]) – 
output_type (Optional[Type[Output]]) – 
Return type
Runnable[Input, Output]
property InputType: Type[Input]¶
The type of input this runnable accepts specified as a type annotation.
property OutputType: Type[Output]¶
The type of output this runnable produces specified as a type annotation.
property config_specs: List[ConfigurableFieldSpec]¶
List configurable fields for this runnable.
property input_schema: Type[BaseModel]¶
The type of input this runnable accepts specified as a pydantic model.
property lc_attributes: Dict¶
List of attribute names that should be included in the serialized kwargs.
These attributes must be accepted by the constructor.
property lc_secrets: Dict[str, str]¶
A map of constructor argument names to secret ids.
For example,{“openai_api_key”: “OPENAI_API_KEY”}
name: Optional[str] = None¶
The name of the runnable. Used for debugging and tracing.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
Examples using ArceeRetriever¶
Arcee
langchain.retrievers.self_query.base.SelfQueryRetriever¶
class langchain.retrievers.self_query.base.SelfQueryRetriever[source]¶
Bases: BaseRetriever
Retriever that uses a vector store and an LLM to generate
the vector store queries.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the retriever. Defaults to None
This metadata will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a retriever with its
use case.
param query_constructor: Runnable[dict, StructuredQuery] [Required] (alias 'llm_chain')¶
The query constructor chain for generating the vector store queries.
llm_chain is legacy name kept for backwards compatibility.
param search_kwargs: dict [Optional]¶
Keyword arguments to pass in to the vector store search.
param search_type: str = 'similarity'¶
The search type to perform on the vector store.
param structured_query_translator: Visitor [Required]¶
Translator for turning internal query language into vectorstore search params.
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the retriever. Defaults to None
These tags will be associated with each call to this retriever,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a retriever with its
use case.
param use_original_query: bool = False¶
Use original query instead of the revised new query from LLM
param vectorstore: VectorStore [Required]¶
param vectorstore: VectorStore [Required]¶
The underlying vector store from which documents will be retrieved.
param verbose: bool = False¶
async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶
Default implementation runs ainvoke in parallel using asyncio.gather.
The default implementation of batch works well for IO bound runnables.
Subclasses should override this method if they can batch more efficiently;
e.g., if the underlying runnable uses an API which supports a batch mode.
Parameters
inputs (List[Input]) – 
config (Optional[Union[RunnableConfig, List[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
List[Output]
async abatch_as_completed(inputs: Sequence[Input], config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → AsyncIterator[Tuple[int, Union[Output, Exception]]]¶
Run ainvoke in parallel on a list of inputs,
yielding results as they complete.
Parameters
inputs (Sequence[Input]) – 
config (Optional[Union[RunnableConfig, Sequence[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
AsyncIterator[Tuple[int, Union[Output, Exception]]]
async aget_relevant_documents(query: str, *, callbacks: Callbacks = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, **kwargs: Any) → List[Document]¶
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(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) → DictStrAny¶
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
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) – 
Return type
DictStrAny
classmethod from_llm(llm: BaseLanguageModel, vectorstore: VectorStore, document_contents: str, metadata_field_info: Sequence[Union[AttributeInfo, dict]], structured_query_translator: Optional[Visitor] = None, chain_kwargs: Optional[Dict] = None, enable_limit: bool = False, use_original_query: bool = False, **kwargs: Any) → SelfQueryRetriever[source]¶
Parameters
llm (BaseLanguageModel) – 
vectorstore (VectorStore) – 
document_contents (str) – 
metadata_field_info (Sequence[Union[AttributeInfo, dict]]) –
metadata_field_info (Sequence[Union[AttributeInfo, dict]]) – 
structured_query_translator (Optional[Visitor]) – 
chain_kwargs (Optional[Dict]) – 
enable_limit (bool) – 
use_original_query (bool) – 
kwargs (Any) – 
Return type
SelfQueryRetriever
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
get_graph(config: Optional[RunnableConfig] = None) → Graph¶
Return a graph representation of this runnable.
Parameters
config (Optional[RunnableConfig]) – 
Return type
Graph
get_input_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate input to the runnable.
Runnables that leverage the configurable_fields and configurable_alternatives
methods will have a dynamic input schema that depends on which
configuration the runnable is invoked with.
This method allows to get an input schema for a specific configuration.
Parameters
config (Optional[RunnableConfig]) – A config to use when generating the schema.
Returns
A pydantic model that can be used to validate input.
Return type
Type[BaseModel]
classmethod get_lc_namespace() → List[str]¶
Get the namespace of the langchain object.
For example, if the class is langchain.llms.openai.OpenAI, then the
namespace is [“langchain”, “llms”, “openai”]
Return type
List[str]
get_name(suffix: Optional[str] = None, *, name: Optional[str] = None) → str¶
Get the name of the runnable.
Parameters
suffix (Optional[str]) – 
name (Optional[str]) – 
Return type
str