Tony20100/langchain_full huggingface dataset:
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
methods will have a dynamic output schema that depends on which
configuration the runnable is invoked with.
This method allows to get an output 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 output.
Return type
Type[BaseModel]
get_prompts(config: Optional[RunnableConfig] = None) → List[BasePromptTemplate]¶
Parameters
config (Optional[RunnableConfig]) – 
Return type
List[BasePromptTemplate]
invoke(input: AqaInput, config: Optional[RunnableConfig] = None) → AqaOutput[source]¶
Generates a grounded response using the provided passages.
Parameters
input (AqaInput) – 
config (Optional[RunnableConfig]) – 
Return type
AqaOutput
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]
map() → Runnable[List[Input], List[Output]]¶
langchain_google_genai.genai_aqa.AqaInput¶
class langchain_google_genai.genai_aqa.AqaInput[source]¶
Bases: BaseModel
Input to GenAIAqa.invoke.
prompt¶
The user’s inquiry.
source_passages¶
A list of passage that the LLM should use only to
answer the user’s inquiry.
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 prompt: str [Required]¶
param source_passages: List[str] [Required]¶
classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶
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: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
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
langchain_google_genai.genai_aqa.AqaOutput¶
class langchain_google_genai.genai_aqa.AqaOutput[source]¶
Bases: BaseModel
Output from GenAIAqa.invoke.
answer¶
The answer to the user’s inquiry.
attributed_passages¶
A list of passages that the LLM used to construct
the answer.
answerable_probability¶
The probability of the question being answered
from the provided passages.
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 answer: str [Required]¶
param answerable_probability: float [Required]¶
param attributed_passages: List[str] [Required]¶
classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶
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: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
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
langchain_core.indexing.api.index¶
langchain_core.indexing.api.index(docs_source: Union[BaseLoader, Iterable[Document]], record_manager: RecordManager, vector_store: VectorStore, *, batch_size: int = 100, cleanup: Optional[Literal['incremental', 'full', None]] = None, source_id_key: Optional[Union[str, Callable[[Document], str]]] = None, cleanup_batch_size: int = 1000, force_update: bool = False) → IndexingResult[source]¶
Index data from the loader into the vector store.
Indexing functionality uses a manager to keep track of which documents
are in the vector store.
This allows us to keep track of which documents were updated, and which
documents were deleted, which documents should be skipped.
For the time being, documents are indexed using their hashes, and usersare not able to specify the uid of the document.
Important
if auto_cleanup is set to True, the loader should be returning
the entire dataset, and not just a subset of the dataset.
Otherwise, the auto_cleanup will remove documents that it is not
supposed to.
Parameters
docs_source (Union[BaseLoader, Iterable[Document]]) – Data loader or iterable of documents to index.
record_manager (RecordManager) – Timestamped set to keep track of which documents were
updated.
vector_store (VectorStore) – Vector store to index the documents into.
batch_size (int) – Batch size to use when indexing.
cleanup (Optional[Literal['incremental', 'full', None]]) – How to handle clean up of documents.
- Incremental: Cleans up all documents that haven’t been updated AND
that are associated with source ids that were seen
during indexing.
Clean up is done continuously during indexing helping
to minimize the probability of users seeing duplicated
content.
to minimize the probability of users seeing duplicated
content.
Full: Delete all documents that have not been returned by the loaderduring this run of indexing.
Clean up runs after all documents have been indexed.
This means that users may see duplicated content during indexing.
None: Do not delete any documents.
source_id_key (Optional[Union[str, Callable[[Document], str]]]) – Optional key that helps identify the original source
of the document.
cleanup_batch_size (int) – Batch size to use when cleaning up documents.
force_update (bool) – Force update documents even if they are present in the
record manager. Useful if you are re-indexing with updated embeddings.
Returns
Indexing result which contains information about how many documents
were added, updated, deleted, or skipped.
Return type
IndexingResult
Examples using index¶
How to use the LangChain indexing API
langchain_core.indexing.base.RecordManager¶
class langchain_core.indexing.base.RecordManager(namespace: str)[source]¶
Abstract base class representing the interface for a record manager.
Initialize the record manager.
Parameters
namespace (str) – The namespace for the record manager.
Methods
__init__(namespace)
Initialize the record manager.
acreate_schema()
Asynchronously create the database schema for the record manager.
adelete_keys(keys)
Asynchronously delete specified records from the database.
aexists(keys)
Asynchronously check if the provided keys exist in the database.
aget_time()
Asynchronously get the current server time as a high resolution timestamp.
alist_keys(*[, before, after, group_ids, limit])
Asynchronously list records in the database based on the provided filters.
aupdate(keys, *[, group_ids, time_at_least])
Asynchronously upsert records into the database.
create_schema()
Create the database schema for the record manager.
delete_keys(keys)
Delete specified records from the database.
exists(keys)
Check if the provided keys exist in the database.
get_time()
Get the current server time as a high resolution timestamp!
list_keys(*[, before, after, group_ids, limit])
List records in the database based on the provided filters.
update(keys, *[, group_ids, time_at_least])
Upsert records into the database.
__init__(namespace: str) → None[source]¶
Initialize the record manager.
Parameters
namespace (str) – The namespace for the record manager.
Return type
None
abstract async acreate_schema() → None[source]¶
Asynchronously create the database schema for the record manager.
Return type
None
abstract async adelete_keys(keys: Sequence[str]) → None[source]¶
None
abstract async adelete_keys(keys: Sequence[str]) → None[source]¶
Asynchronously delete specified records from the database.
Parameters
keys (Sequence[str]) – A list of keys to delete.
Return type
None
abstract async aexists(keys: Sequence[str]) → List[bool][source]¶
Asynchronously check if the provided keys exist in the database.
Parameters
keys (Sequence[str]) – A list of keys to check.
Returns
A list of boolean values indicating the existence of each key.
Return type
List[bool]
abstract async aget_time() → float[source]¶
Asynchronously get the current server time as a high resolution timestamp.
It’s important to get this from the server to ensure a monotonic clock,
otherwise there may be data loss when cleaning up old documents!
Returns
The current server time as a float timestamp.
Return type
float
abstract async alist_keys(*, before: Optional[float] = None, after: Optional[float] = None, group_ids: Optional[Sequence[str]] = None, limit: Optional[int] = None) → List[str][source]¶
Asynchronously list records in the database based on the provided filters.
Parameters
before (Optional[float]) – Filter to list records updated before this time.
after (Optional[float]) – Filter to list records updated after this time.
group_ids (Optional[Sequence[str]]) – Filter to list records with specific group IDs.
limit (Optional[int]) – optional limit on the number of records to return.
Returns
A list of keys for the matching records.
Return type
List[str]
abstract async aupdate(keys: Sequence[str], *, group_ids: Optional[Sequence[Optional[str]]] = None, time_at_least: Optional[float] = None) → None[source]¶
Asynchronously upsert records into the database.
Parameters
Asynchronously upsert records into the database.
Parameters
keys (Sequence[str]) – A list of record keys to upsert.
group_ids (Optional[Sequence[Optional[str]]]) – A list of group IDs corresponding to the keys.
time_at_least (Optional[float]) – Optional timestamp. Implementation can use this
to optionally verify that the timestamp IS at least this time
in the system that stores the data.
e.g., use to validate that the time in the postgres database
is equal to or larger than the given timestamp, if not
raise an error.
This is meant to help prevent time-drift issues since
time may not be monotonically increasing!
Raises
ValueError – If the length of keys doesn’t match the length of group_ids.
Return type
None
abstract create_schema() → None[source]¶
Create the database schema for the record manager.
Return type
None
abstract delete_keys(keys: Sequence[str]) → None[source]¶
Delete specified records from the database.
Parameters
keys (Sequence[str]) – A list of keys to delete.
Return type
None
abstract exists(keys: Sequence[str]) → List[bool][source]¶
Check if the provided keys exist in the database.
Parameters
keys (Sequence[str]) – A list of keys to check.
Returns
A list of boolean values indicating the existence of each key.
Return type
List[bool]
abstract get_time() → float[source]¶
Get the current server time as a high resolution timestamp!
It’s important to get this from the server to ensure a monotonic clock,
otherwise there may be data loss when cleaning up old documents!
Returns
The current server time as a float timestamp.
Return type
float
Returns
The current server time as a float timestamp.
Return type
float
abstract list_keys(*, before: Optional[float] = None, after: Optional[float] = None, group_ids: Optional[Sequence[str]] = None, limit: Optional[int] = None) → List[str][source]¶
List records in the database based on the provided filters.
Parameters
before (Optional[float]) – Filter to list records updated before this time.
after (Optional[float]) – Filter to list records updated after this time.
group_ids (Optional[Sequence[str]]) – Filter to list records with specific group IDs.
limit (Optional[int]) – optional limit on the number of records to return.
Returns
A list of keys for the matching records.
Return type
List[str]
abstract update(keys: Sequence[str], *, group_ids: Optional[Sequence[Optional[str]]] = None, time_at_least: Optional[float] = None) → None[source]¶
Upsert records into the database.
Parameters
keys (Sequence[str]) – A list of record keys to upsert.
group_ids (Optional[Sequence[Optional[str]]]) – A list of group IDs corresponding to the keys.
time_at_least (Optional[float]) – Optional timestamp. Implementation can use this
to optionally verify that the timestamp IS at least this time
in the system that stores the data.
e.g., use to validate that the time in the postgres database
is equal to or larger than the given timestamp, if not
raise an error.
This is meant to help prevent time-drift issues since
time may not be monotonically increasing!
Raises
ValueError – If the length of keys doesn’t match the length of group_ids.
Return type
None
langchain_core.indexing.api.aindex¶
async langchain_core.indexing.api.aindex(docs_source: Union[BaseLoader, Iterable[Document], AsyncIterator[Document]], record_manager: RecordManager, vector_store: VectorStore, *, batch_size: int = 100, cleanup: Optional[Literal['incremental', 'full', None]] = None, source_id_key: Optional[Union[str, Callable[[Document], str]]] = None, cleanup_batch_size: int = 1000, force_update: bool = False) → IndexingResult[source]¶
Index data from the loader into the vector store.
Indexing functionality uses a manager to keep track of which documents
are in the vector store.
This allows us to keep track of which documents were updated, and which
documents were deleted, which documents should be skipped.
For the time being, documents are indexed using their hashes, and usersare not able to specify the uid of the document.
Important
if auto_cleanup is set to True, the loader should be returning
the entire dataset, and not just a subset of the dataset.
Otherwise, the auto_cleanup will remove documents that it is not
supposed to.
Parameters
docs_source (Union[BaseLoader, Iterable[Document], AsyncIterator[Document]]) – Data loader or iterable of documents to index.
record_manager (RecordManager) – Timestamped set to keep track of which documents were
updated.
vector_store (VectorStore) – Vector store to index the documents into.
batch_size (int) – Batch size to use when indexing.
cleanup (Optional[Literal['incremental', 'full', None]]) – How to handle clean up of documents.
- Incremental: Cleans up all documents that haven’t been updated AND
that are associated with source ids that were seen
during indexing.
Clean up is done continuously during indexing helping
during indexing.
Clean up is done continuously during indexing helping
to minimize the probability of users seeing duplicated
content.
Full: Delete all documents that haven to been returned by the loader.Clean up runs after all documents have been indexed.
This means that users may see duplicated content during indexing.
None: Do not delete any documents.
source_id_key (Optional[Union[str, Callable[[Document], str]]]) – Optional key that helps identify the original source
of the document.
cleanup_batch_size (int) – Batch size to use when cleaning up documents.
force_update (bool) – Force update documents even if they are present in the
record manager. Useful if you are re-indexing with updated embeddings.
Returns
Indexing result which contains information about how many documents
were added, updated, deleted, or skipped.
Return type
IndexingResult
langchain_core.indexing.api.IndexingResult¶
class langchain_core.indexing.api.IndexingResult[source]¶
Return a detailed a breakdown of the result of the indexing operation.
num_added: int¶
Number of added documents.
num_updated: int¶
Number of updated documents because they were not up to date.
num_deleted: int¶
Number of deleted documents.
num_skipped: int¶
Number of skipped documents because they were already up to date.
langchain_google_community.translate.GoogleTranslateTransformer¶
class langchain_google_community.translate.GoogleTranslateTransformer(project_id: str, *, location: str = 'global', model_id: Optional[str] = None, glossary_id: Optional[str] = None, api_endpoint: Optional[str] = None)[source]¶
Translate text documents using Google Cloud Translation.
Parameters
project_id (str) – Google Cloud Project ID.
location (str) – (Optional) Translate model location.
model_id (Optional[str]) – (Optional) Translate model ID to use.
glossary_id (Optional[str]) – (Optional) Translate glossary ID to use.
api_endpoint (Optional[str]) – (Optional) Regional endpoint to use.
Methods
__init__(project_id, *[, location, ...])
param project_id
Google Cloud Project ID.
atransform_documents(documents, **kwargs)
Asynchronously transform a list of documents.
transform_documents(documents, **kwargs)
Translate text documents using Google Translate.
__init__(project_id: str, *, location: str = 'global', model_id: Optional[str] = None, glossary_id: Optional[str] = None, api_endpoint: Optional[str] = None) → None[source]¶
Parameters
project_id (str) – Google Cloud Project ID.
location (str) – (Optional) Translate model location.
model_id (Optional[str]) – (Optional) Translate model ID to use.
glossary_id (Optional[str]) – (Optional) Translate glossary ID to use.
api_endpoint (Optional[str]) – (Optional) Regional endpoint to use.
Return type
None
async atransform_documents(documents: Sequence[Document], **kwargs: Any) → Sequence[Document]¶
Asynchronously transform a list of documents.
Parameters
langchain_google_community.search.GoogleSearchRun¶
class langchain_google_community.search.GoogleSearchRun[source]¶
Bases: BaseTool
Tool that queries the Google search API.
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 api_wrapper: GoogleSearchAPIWrapper [Required]¶
param args_schema: Optional[Type[BaseModel]] = None¶
Pydantic model class to validate and parse the tool’s input arguments.
param callback_manager: Optional[BaseCallbackManager] = None¶
Deprecated. Please use callbacks instead.
param callbacks: Callbacks = None¶
Callbacks to be called during tool execution.
param description: str = 'A wrapper around Google Search. Useful for when you need to answer questions about current events. Input should be a search query.'¶
Used to tell the model how/when/why to use the tool.
You can provide few-shot examples as a part of the description.
param handle_tool_error: Optional[Union[bool, str, Callable[[ToolException], str]]] = False¶
Handle the content of the ToolException thrown.
param handle_validation_error: Optional[Union[bool, str, Callable[[ValidationError], str]]] = False¶
Handle the content of the ValidationError thrown.
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the tool. Defaults to None
This metadata will be associated with each call to this tool,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a tool with its use case.
param return_direct: bool = False¶
Whether to return the tool’s output directly. Setting this to True means
that after the tool is called, the AgentExecutor will stop looping.
langchain_google_community.search.GoogleSearchAPIWrapper¶
class langchain_google_community.search.GoogleSearchAPIWrapper[source]¶
Bases: BaseModel
Wrapper for Google Search API.
Adapted from: Instructions adapted from https://stackoverflow.com/questions/
37083058/
programmatically-searching-google-in-python-using-custom-search
TODO: DOCS for using it
1. Install google-api-python-client
- If you don’t already have a Google account, sign up.
- If you have never created a Google APIs Console project,
read the Managing Projects page and create a project in the Google API Console.
- Install the library using pip install google-api-python-client
2. Enable the Custom Search API
- Navigate to the APIs & Services→Dashboard panel in Cloud Console.
- Click Enable APIs and Services.
- Search for Custom Search API and click on it.
- Click Enable.
URL for it: https://console.cloud.google.com/apis/library/customsearch.googleapis
.com
3. To create an API key:
- Navigate to the APIs & Services → Credentials panel in Cloud Console.
- Select Create credentials, then select API key from the drop-down menu.
- The API key created dialog box displays your newly created key.
- You now have an API_KEY
Alternatively, you can just generate an API key here:
https://developers.google.com/custom-search/docs/paid_element#api_key
4. Setup Custom Search Engine so you can search the entire web
- Create a custom search engine here: https://programmablesearchengine.google.com/.
- In What to search to search, pick the Search the entire Web option.
After search engine is created, you can click on it and find Search engine ID
on the Overview page.
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.