langchain-core 1.0.0a6__py3-none-any.whl → 1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langchain_core/__init__.py +1 -1
- langchain_core/_api/__init__.py +3 -4
- langchain_core/_api/beta_decorator.py +23 -26
- langchain_core/_api/deprecation.py +51 -64
- langchain_core/_api/path.py +3 -6
- langchain_core/_import_utils.py +3 -4
- langchain_core/agents.py +20 -22
- langchain_core/caches.py +65 -66
- langchain_core/callbacks/__init__.py +1 -8
- langchain_core/callbacks/base.py +321 -336
- langchain_core/callbacks/file.py +44 -44
- langchain_core/callbacks/manager.py +436 -513
- langchain_core/callbacks/stdout.py +29 -30
- langchain_core/callbacks/streaming_stdout.py +32 -32
- langchain_core/callbacks/usage.py +60 -57
- langchain_core/chat_history.py +53 -68
- langchain_core/document_loaders/base.py +27 -25
- langchain_core/document_loaders/blob_loaders.py +1 -1
- langchain_core/document_loaders/langsmith.py +44 -48
- langchain_core/documents/__init__.py +23 -3
- langchain_core/documents/base.py +98 -90
- langchain_core/documents/compressor.py +10 -10
- langchain_core/documents/transformers.py +34 -35
- langchain_core/embeddings/fake.py +50 -54
- langchain_core/example_selectors/length_based.py +1 -1
- langchain_core/example_selectors/semantic_similarity.py +28 -32
- langchain_core/exceptions.py +21 -20
- langchain_core/globals.py +3 -151
- langchain_core/indexing/__init__.py +1 -1
- langchain_core/indexing/api.py +121 -126
- langchain_core/indexing/base.py +73 -75
- langchain_core/indexing/in_memory.py +4 -6
- langchain_core/language_models/__init__.py +14 -29
- langchain_core/language_models/_utils.py +58 -61
- langchain_core/language_models/base.py +53 -162
- langchain_core/language_models/chat_models.py +298 -387
- langchain_core/language_models/fake.py +11 -11
- langchain_core/language_models/fake_chat_models.py +42 -36
- langchain_core/language_models/llms.py +125 -235
- langchain_core/load/dump.py +9 -12
- langchain_core/load/load.py +18 -28
- langchain_core/load/mapping.py +2 -4
- langchain_core/load/serializable.py +42 -40
- langchain_core/messages/__init__.py +10 -16
- langchain_core/messages/ai.py +148 -148
- langchain_core/messages/base.py +53 -51
- langchain_core/messages/block_translators/__init__.py +19 -22
- langchain_core/messages/block_translators/anthropic.py +6 -6
- langchain_core/messages/block_translators/bedrock_converse.py +5 -5
- langchain_core/messages/block_translators/google_genai.py +10 -7
- langchain_core/messages/block_translators/google_vertexai.py +4 -32
- langchain_core/messages/block_translators/groq.py +117 -21
- langchain_core/messages/block_translators/langchain_v0.py +5 -5
- langchain_core/messages/block_translators/openai.py +11 -11
- langchain_core/messages/chat.py +2 -6
- langchain_core/messages/content.py +337 -328
- langchain_core/messages/function.py +6 -10
- langchain_core/messages/human.py +24 -31
- langchain_core/messages/modifier.py +2 -2
- langchain_core/messages/system.py +19 -29
- langchain_core/messages/tool.py +74 -90
- langchain_core/messages/utils.py +474 -504
- langchain_core/output_parsers/__init__.py +13 -10
- langchain_core/output_parsers/base.py +61 -61
- langchain_core/output_parsers/format_instructions.py +9 -4
- langchain_core/output_parsers/json.py +12 -10
- langchain_core/output_parsers/list.py +21 -23
- langchain_core/output_parsers/openai_functions.py +49 -47
- langchain_core/output_parsers/openai_tools.py +16 -21
- langchain_core/output_parsers/pydantic.py +13 -14
- langchain_core/output_parsers/string.py +5 -5
- langchain_core/output_parsers/transform.py +15 -17
- langchain_core/output_parsers/xml.py +35 -34
- langchain_core/outputs/__init__.py +1 -1
- langchain_core/outputs/chat_generation.py +18 -18
- langchain_core/outputs/chat_result.py +1 -3
- langchain_core/outputs/generation.py +10 -11
- langchain_core/outputs/llm_result.py +10 -10
- langchain_core/prompt_values.py +11 -17
- langchain_core/prompts/__init__.py +3 -27
- langchain_core/prompts/base.py +48 -56
- langchain_core/prompts/chat.py +275 -325
- langchain_core/prompts/dict.py +5 -5
- langchain_core/prompts/few_shot.py +81 -88
- langchain_core/prompts/few_shot_with_templates.py +11 -13
- langchain_core/prompts/image.py +12 -14
- langchain_core/prompts/loading.py +4 -6
- langchain_core/prompts/message.py +3 -3
- langchain_core/prompts/prompt.py +24 -39
- langchain_core/prompts/string.py +26 -10
- langchain_core/prompts/structured.py +49 -53
- langchain_core/rate_limiters.py +51 -60
- langchain_core/retrievers.py +61 -198
- langchain_core/runnables/base.py +1476 -1626
- langchain_core/runnables/branch.py +53 -57
- langchain_core/runnables/config.py +72 -89
- langchain_core/runnables/configurable.py +120 -137
- langchain_core/runnables/fallbacks.py +83 -79
- langchain_core/runnables/graph.py +91 -97
- langchain_core/runnables/graph_ascii.py +27 -28
- langchain_core/runnables/graph_mermaid.py +38 -50
- langchain_core/runnables/graph_png.py +15 -16
- langchain_core/runnables/history.py +135 -148
- langchain_core/runnables/passthrough.py +124 -150
- langchain_core/runnables/retry.py +46 -51
- langchain_core/runnables/router.py +25 -30
- langchain_core/runnables/schema.py +75 -80
- langchain_core/runnables/utils.py +60 -67
- langchain_core/stores.py +85 -121
- langchain_core/structured_query.py +8 -8
- langchain_core/sys_info.py +27 -29
- langchain_core/tools/__init__.py +1 -14
- langchain_core/tools/base.py +284 -229
- langchain_core/tools/convert.py +160 -155
- langchain_core/tools/render.py +10 -10
- langchain_core/tools/retriever.py +12 -11
- langchain_core/tools/simple.py +19 -24
- langchain_core/tools/structured.py +32 -39
- langchain_core/tracers/__init__.py +1 -9
- langchain_core/tracers/base.py +97 -99
- langchain_core/tracers/context.py +29 -52
- langchain_core/tracers/core.py +49 -53
- langchain_core/tracers/evaluation.py +11 -11
- langchain_core/tracers/event_stream.py +65 -64
- langchain_core/tracers/langchain.py +21 -21
- langchain_core/tracers/log_stream.py +45 -45
- langchain_core/tracers/memory_stream.py +3 -3
- langchain_core/tracers/root_listeners.py +16 -16
- langchain_core/tracers/run_collector.py +2 -4
- langchain_core/tracers/schemas.py +0 -129
- langchain_core/tracers/stdout.py +3 -3
- langchain_core/utils/__init__.py +1 -4
- langchain_core/utils/_merge.py +2 -2
- langchain_core/utils/aiter.py +57 -61
- langchain_core/utils/env.py +9 -9
- langchain_core/utils/function_calling.py +89 -186
- langchain_core/utils/html.py +7 -8
- langchain_core/utils/input.py +6 -6
- langchain_core/utils/interactive_env.py +1 -1
- langchain_core/utils/iter.py +36 -40
- langchain_core/utils/json.py +4 -3
- langchain_core/utils/json_schema.py +9 -9
- langchain_core/utils/mustache.py +8 -10
- langchain_core/utils/pydantic.py +33 -35
- langchain_core/utils/strings.py +6 -9
- langchain_core/utils/usage.py +1 -1
- langchain_core/utils/utils.py +66 -62
- langchain_core/vectorstores/base.py +182 -216
- langchain_core/vectorstores/in_memory.py +101 -176
- langchain_core/vectorstores/utils.py +5 -5
- langchain_core/version.py +1 -1
- langchain_core-1.0.3.dist-info/METADATA +69 -0
- langchain_core-1.0.3.dist-info/RECORD +172 -0
- {langchain_core-1.0.0a6.dist-info → langchain_core-1.0.3.dist-info}/WHEEL +1 -1
- langchain_core/memory.py +0 -120
- langchain_core/messages/block_translators/ollama.py +0 -47
- langchain_core/prompts/pipeline.py +0 -138
- langchain_core/pydantic_v1/__init__.py +0 -30
- langchain_core/pydantic_v1/dataclasses.py +0 -23
- langchain_core/pydantic_v1/main.py +0 -23
- langchain_core/tracers/langchain_v1.py +0 -31
- langchain_core/utils/loading.py +0 -35
- langchain_core-1.0.0a6.dist-info/METADATA +0 -67
- langchain_core-1.0.0a6.dist-info/RECORD +0 -181
- langchain_core-1.0.0a6.dist-info/entry_points.txt +0 -4
langchain_core/retrievers.py
CHANGED
|
@@ -3,34 +3,17 @@
|
|
|
3
3
|
It is more general than a vector store. A retriever does not need to be able to
|
|
4
4
|
store documents, only to return (or retrieve) it. Vector stores can be used as
|
|
5
5
|
the backbone of a retriever, but there are other types of retrievers as well.
|
|
6
|
-
|
|
7
|
-
**Class hierarchy:**
|
|
8
|
-
|
|
9
|
-
.. code-block::
|
|
10
|
-
|
|
11
|
-
BaseRetriever --> <name>Retriever # Examples: ArxivRetriever, MergerRetriever
|
|
12
|
-
|
|
13
|
-
**Main helpers:**
|
|
14
|
-
|
|
15
|
-
.. code-block::
|
|
16
|
-
|
|
17
|
-
RetrieverInput, RetrieverOutput, RetrieverLike, RetrieverOutputLike,
|
|
18
|
-
Document, Serializable, Callbacks,
|
|
19
|
-
CallbackManagerForRetrieverRun, AsyncCallbackManagerForRetrieverRun
|
|
20
6
|
"""
|
|
21
7
|
|
|
22
8
|
from __future__ import annotations
|
|
23
9
|
|
|
24
|
-
import warnings
|
|
25
10
|
from abc import ABC, abstractmethod
|
|
26
11
|
from inspect import signature
|
|
27
|
-
from typing import TYPE_CHECKING, Any
|
|
12
|
+
from typing import TYPE_CHECKING, Any
|
|
28
13
|
|
|
29
14
|
from pydantic import ConfigDict
|
|
30
15
|
from typing_extensions import Self, TypedDict, override
|
|
31
16
|
|
|
32
|
-
from langchain_core._api import deprecated
|
|
33
|
-
from langchain_core.callbacks import Callbacks
|
|
34
17
|
from langchain_core.callbacks.manager import AsyncCallbackManager, CallbackManager
|
|
35
18
|
from langchain_core.documents import Document
|
|
36
19
|
from langchain_core.runnables import (
|
|
@@ -58,77 +41,74 @@ class LangSmithRetrieverParams(TypedDict, total=False):
|
|
|
58
41
|
|
|
59
42
|
ls_retriever_name: str
|
|
60
43
|
"""Retriever name."""
|
|
61
|
-
ls_vector_store_provider:
|
|
44
|
+
ls_vector_store_provider: str | None
|
|
62
45
|
"""Vector store provider."""
|
|
63
|
-
ls_embedding_provider:
|
|
46
|
+
ls_embedding_provider: str | None
|
|
64
47
|
"""Embedding provider."""
|
|
65
|
-
ls_embedding_model:
|
|
48
|
+
ls_embedding_model: str | None
|
|
66
49
|
"""Embedding model."""
|
|
67
50
|
|
|
68
51
|
|
|
69
52
|
class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
|
|
70
|
-
"""Abstract base class for a
|
|
53
|
+
"""Abstract base class for a document retrieval system.
|
|
71
54
|
|
|
72
55
|
A retrieval system is defined as something that can take string queries and return
|
|
73
|
-
the most 'relevant'
|
|
56
|
+
the most 'relevant' documents from some source.
|
|
74
57
|
|
|
75
58
|
Usage:
|
|
76
59
|
|
|
77
|
-
A retriever follows the standard Runnable interface, and should be used
|
|
78
|
-
|
|
60
|
+
A retriever follows the standard `Runnable` interface, and should be used via the
|
|
61
|
+
standard `Runnable` methods of `invoke`, `ainvoke`, `batch`, `abatch`.
|
|
79
62
|
|
|
80
63
|
Implementation:
|
|
81
64
|
|
|
82
|
-
When implementing a custom retriever, the class should implement
|
|
83
|
-
|
|
65
|
+
When implementing a custom retriever, the class should implement the
|
|
66
|
+
`_get_relevant_documents` method to define the logic for retrieving documents.
|
|
84
67
|
|
|
85
68
|
Optionally, an async native implementations can be provided by overriding the
|
|
86
69
|
`_aget_relevant_documents` method.
|
|
87
70
|
|
|
88
|
-
|
|
71
|
+
!!! example "Retriever that returns the first 5 documents from a list of documents"
|
|
89
72
|
|
|
90
|
-
|
|
73
|
+
```python
|
|
74
|
+
from langchain_core.documents import Document
|
|
75
|
+
from langchain_core.retrievers import BaseRetriever
|
|
91
76
|
|
|
92
|
-
|
|
93
|
-
|
|
77
|
+
class SimpleRetriever(BaseRetriever):
|
|
78
|
+
docs: list[Document]
|
|
79
|
+
k: int = 5
|
|
94
80
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
k
|
|
81
|
+
def _get_relevant_documents(self, query: str) -> list[Document]:
|
|
82
|
+
\"\"\"Return the first k documents from the list of documents\"\"\"
|
|
83
|
+
return self.docs[:self.k]
|
|
98
84
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
async def _aget_relevant_documents(self, query: str) -> list[Document]:
|
|
86
|
+
\"\"\"(Optional) async native implementation.\"\"\"
|
|
87
|
+
return self.docs[:self.k]
|
|
88
|
+
```
|
|
102
89
|
|
|
103
|
-
|
|
104
|
-
\"\"\"(Optional) async native implementation.\"\"\"
|
|
105
|
-
return self.docs[:self.k]
|
|
90
|
+
!!! example "Simple retriever based on a scikit-learn vectorizer"
|
|
106
91
|
|
|
107
|
-
|
|
92
|
+
```python
|
|
93
|
+
from sklearn.metrics.pairwise import cosine_similarity
|
|
108
94
|
|
|
109
|
-
.. code-block:: python
|
|
110
95
|
|
|
111
|
-
|
|
96
|
+
class TFIDFRetriever(BaseRetriever, BaseModel):
|
|
97
|
+
vectorizer: Any
|
|
98
|
+
docs: list[Document]
|
|
99
|
+
tfidf_array: Any
|
|
100
|
+
k: int = 4
|
|
112
101
|
|
|
102
|
+
class Config:
|
|
103
|
+
arbitrary_types_allowed = True
|
|
113
104
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
arbitrary_types_allowed = True
|
|
122
|
-
|
|
123
|
-
def _get_relevant_documents(self, query: str) -> list[Document]:
|
|
124
|
-
# Ip -- (n_docs,x), Op -- (n_docs,n_Feats)
|
|
125
|
-
query_vec = self.vectorizer.transform([query])
|
|
126
|
-
# Op -- (n_docs,1) -- Cosine Sim with each doc
|
|
127
|
-
results = cosine_similarity(self.tfidf_array, query_vec).reshape(
|
|
128
|
-
(-1,)
|
|
129
|
-
)
|
|
130
|
-
return [self.docs[i] for i in results.argsort()[-self.k :][::-1]]
|
|
131
|
-
|
|
105
|
+
def _get_relevant_documents(self, query: str) -> list[Document]:
|
|
106
|
+
# Ip -- (n_docs,x), Op -- (n_docs,n_Feats)
|
|
107
|
+
query_vec = self.vectorizer.transform([query])
|
|
108
|
+
# Op -- (n_docs,1) -- Cosine Sim with each doc
|
|
109
|
+
results = cosine_similarity(self.tfidf_array, query_vec).reshape((-1,))
|
|
110
|
+
return [self.docs[i] for i in results.argsort()[-self.k :][::-1]]
|
|
111
|
+
```
|
|
132
112
|
"""
|
|
133
113
|
|
|
134
114
|
model_config = ConfigDict(
|
|
@@ -137,17 +117,21 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
|
|
|
137
117
|
|
|
138
118
|
_new_arg_supported: bool = False
|
|
139
119
|
_expects_other_args: bool = False
|
|
140
|
-
tags:
|
|
141
|
-
"""Optional list of tags associated with the retriever.
|
|
120
|
+
tags: list[str] | None = None
|
|
121
|
+
"""Optional list of tags associated with the retriever.
|
|
122
|
+
|
|
142
123
|
These tags will be associated with each call to this retriever,
|
|
143
124
|
and passed as arguments to the handlers defined in `callbacks`.
|
|
125
|
+
|
|
144
126
|
You can use these to eg identify a specific instance of a retriever with its
|
|
145
127
|
use case.
|
|
146
128
|
"""
|
|
147
|
-
metadata:
|
|
148
|
-
"""Optional metadata associated with the retriever.
|
|
129
|
+
metadata: dict[str, Any] | None = None
|
|
130
|
+
"""Optional metadata associated with the retriever.
|
|
131
|
+
|
|
149
132
|
This metadata will be associated with each call to this retriever,
|
|
150
133
|
and passed as arguments to the handlers defined in `callbacks`.
|
|
134
|
+
|
|
151
135
|
You can use these to eg identify a specific instance of a retriever with its
|
|
152
136
|
use case.
|
|
153
137
|
"""
|
|
@@ -155,35 +139,6 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
|
|
|
155
139
|
@override
|
|
156
140
|
def __init_subclass__(cls, **kwargs: Any) -> None:
|
|
157
141
|
super().__init_subclass__(**kwargs)
|
|
158
|
-
# Version upgrade for old retrievers that implemented the public
|
|
159
|
-
# methods directly.
|
|
160
|
-
if cls.get_relevant_documents != BaseRetriever.get_relevant_documents:
|
|
161
|
-
warnings.warn(
|
|
162
|
-
"Retrievers must implement abstract `_get_relevant_documents` method"
|
|
163
|
-
" instead of `get_relevant_documents`",
|
|
164
|
-
DeprecationWarning,
|
|
165
|
-
stacklevel=4,
|
|
166
|
-
)
|
|
167
|
-
swap = cls.get_relevant_documents
|
|
168
|
-
cls.get_relevant_documents = ( # type: ignore[method-assign]
|
|
169
|
-
BaseRetriever.get_relevant_documents
|
|
170
|
-
)
|
|
171
|
-
cls._get_relevant_documents = swap # type: ignore[method-assign]
|
|
172
|
-
if (
|
|
173
|
-
hasattr(cls, "aget_relevant_documents")
|
|
174
|
-
and cls.aget_relevant_documents != BaseRetriever.aget_relevant_documents
|
|
175
|
-
):
|
|
176
|
-
warnings.warn(
|
|
177
|
-
"Retrievers must implement abstract `_aget_relevant_documents` method"
|
|
178
|
-
" instead of `aget_relevant_documents`",
|
|
179
|
-
DeprecationWarning,
|
|
180
|
-
stacklevel=4,
|
|
181
|
-
)
|
|
182
|
-
aswap = cls.aget_relevant_documents
|
|
183
|
-
cls.aget_relevant_documents = ( # type: ignore[method-assign]
|
|
184
|
-
BaseRetriever.aget_relevant_documents
|
|
185
|
-
)
|
|
186
|
-
cls._aget_relevant_documents = aswap # type: ignore[method-assign]
|
|
187
142
|
parameters = signature(cls._get_relevant_documents).parameters
|
|
188
143
|
cls._new_arg_supported = parameters.get("run_manager") is not None
|
|
189
144
|
if (
|
|
@@ -216,7 +171,7 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
|
|
|
216
171
|
|
|
217
172
|
@override
|
|
218
173
|
def invoke(
|
|
219
|
-
self, input: str, config:
|
|
174
|
+
self, input: str, config: RunnableConfig | None = None, **kwargs: Any
|
|
220
175
|
) -> list[Document]:
|
|
221
176
|
"""Invoke the retriever to get relevant documents.
|
|
222
177
|
|
|
@@ -224,18 +179,16 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
|
|
|
224
179
|
|
|
225
180
|
Args:
|
|
226
181
|
input: The query string.
|
|
227
|
-
config: Configuration for the retriever.
|
|
228
|
-
kwargs: Additional arguments to pass to the retriever.
|
|
182
|
+
config: Configuration for the retriever.
|
|
183
|
+
**kwargs: Additional arguments to pass to the retriever.
|
|
229
184
|
|
|
230
185
|
Returns:
|
|
231
186
|
List of relevant documents.
|
|
232
187
|
|
|
233
188
|
Examples:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
retriever.invoke("query")
|
|
238
|
-
|
|
189
|
+
```python
|
|
190
|
+
retriever.invoke("query")
|
|
191
|
+
```
|
|
239
192
|
"""
|
|
240
193
|
config = ensure_config(config)
|
|
241
194
|
inheritable_metadata = {
|
|
@@ -278,7 +231,7 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
|
|
|
278
231
|
async def ainvoke(
|
|
279
232
|
self,
|
|
280
233
|
input: str,
|
|
281
|
-
config:
|
|
234
|
+
config: RunnableConfig | None = None,
|
|
282
235
|
**kwargs: Any,
|
|
283
236
|
) -> list[Document]:
|
|
284
237
|
"""Asynchronously invoke the retriever to get relevant documents.
|
|
@@ -287,18 +240,16 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
|
|
|
287
240
|
|
|
288
241
|
Args:
|
|
289
242
|
input: The query string.
|
|
290
|
-
config: Configuration for the retriever.
|
|
291
|
-
kwargs: Additional arguments to pass to the retriever.
|
|
243
|
+
config: Configuration for the retriever.
|
|
244
|
+
**kwargs: Additional arguments to pass to the retriever.
|
|
292
245
|
|
|
293
246
|
Returns:
|
|
294
247
|
List of relevant documents.
|
|
295
248
|
|
|
296
249
|
Examples:
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
await retriever.ainvoke("query")
|
|
301
|
-
|
|
250
|
+
```python
|
|
251
|
+
await retriever.ainvoke("query")
|
|
252
|
+
```
|
|
302
253
|
"""
|
|
303
254
|
config = ensure_config(config)
|
|
304
255
|
inheritable_metadata = {
|
|
@@ -369,91 +320,3 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
|
|
|
369
320
|
query,
|
|
370
321
|
run_manager=run_manager.get_sync(),
|
|
371
322
|
)
|
|
372
|
-
|
|
373
|
-
@deprecated(since="0.1.46", alternative="invoke", removal="1.0")
|
|
374
|
-
def get_relevant_documents(
|
|
375
|
-
self,
|
|
376
|
-
query: str,
|
|
377
|
-
*,
|
|
378
|
-
callbacks: Callbacks = None,
|
|
379
|
-
tags: Optional[list[str]] = None,
|
|
380
|
-
metadata: Optional[dict[str, Any]] = None,
|
|
381
|
-
run_name: Optional[str] = None,
|
|
382
|
-
**kwargs: Any,
|
|
383
|
-
) -> list[Document]:
|
|
384
|
-
"""Retrieve documents relevant to a query.
|
|
385
|
-
|
|
386
|
-
Users should favor using `.invoke` or `.batch` rather than
|
|
387
|
-
`get_relevant_documents directly`.
|
|
388
|
-
|
|
389
|
-
Args:
|
|
390
|
-
query: string to find relevant documents for.
|
|
391
|
-
callbacks: Callback manager or list of callbacks. Defaults to None.
|
|
392
|
-
tags: Optional list of tags associated with the retriever.
|
|
393
|
-
These tags will be associated with each call to this retriever,
|
|
394
|
-
and passed as arguments to the handlers defined in `callbacks`.
|
|
395
|
-
Defaults to None.
|
|
396
|
-
metadata: Optional metadata associated with the retriever.
|
|
397
|
-
This metadata will be associated with each call to this retriever,
|
|
398
|
-
and passed as arguments to the handlers defined in `callbacks`.
|
|
399
|
-
Defaults to None.
|
|
400
|
-
run_name: Optional name for the run. Defaults to None.
|
|
401
|
-
kwargs: Additional arguments to pass to the retriever.
|
|
402
|
-
|
|
403
|
-
Returns:
|
|
404
|
-
List of relevant documents.
|
|
405
|
-
"""
|
|
406
|
-
config: RunnableConfig = {}
|
|
407
|
-
if callbacks:
|
|
408
|
-
config["callbacks"] = callbacks
|
|
409
|
-
if tags:
|
|
410
|
-
config["tags"] = tags
|
|
411
|
-
if metadata:
|
|
412
|
-
config["metadata"] = metadata
|
|
413
|
-
if run_name:
|
|
414
|
-
config["run_name"] = run_name
|
|
415
|
-
return self.invoke(query, config, **kwargs)
|
|
416
|
-
|
|
417
|
-
@deprecated(since="0.1.46", alternative="ainvoke", removal="1.0")
|
|
418
|
-
async def aget_relevant_documents(
|
|
419
|
-
self,
|
|
420
|
-
query: str,
|
|
421
|
-
*,
|
|
422
|
-
callbacks: Callbacks = None,
|
|
423
|
-
tags: Optional[list[str]] = None,
|
|
424
|
-
metadata: Optional[dict[str, Any]] = None,
|
|
425
|
-
run_name: Optional[str] = None,
|
|
426
|
-
**kwargs: Any,
|
|
427
|
-
) -> list[Document]:
|
|
428
|
-
"""Asynchronously get documents relevant to a query.
|
|
429
|
-
|
|
430
|
-
Users should favor using `.ainvoke` or `.abatch` rather than
|
|
431
|
-
`aget_relevant_documents directly`.
|
|
432
|
-
|
|
433
|
-
Args:
|
|
434
|
-
query: string to find relevant documents for.
|
|
435
|
-
callbacks: Callback manager or list of callbacks.
|
|
436
|
-
tags: Optional list of tags associated with the retriever.
|
|
437
|
-
These tags will be associated with each call to this retriever,
|
|
438
|
-
and passed as arguments to the handlers defined in `callbacks`.
|
|
439
|
-
Defaults to None.
|
|
440
|
-
metadata: Optional metadata associated with the retriever.
|
|
441
|
-
This metadata will be associated with each call to this retriever,
|
|
442
|
-
and passed as arguments to the handlers defined in `callbacks`.
|
|
443
|
-
Defaults to None.
|
|
444
|
-
run_name: Optional name for the run. Defaults to None.
|
|
445
|
-
kwargs: Additional arguments to pass to the retriever.
|
|
446
|
-
|
|
447
|
-
Returns:
|
|
448
|
-
List of relevant documents.
|
|
449
|
-
"""
|
|
450
|
-
config: RunnableConfig = {}
|
|
451
|
-
if callbacks:
|
|
452
|
-
config["callbacks"] = callbacks
|
|
453
|
-
if tags:
|
|
454
|
-
config["tags"] = tags
|
|
455
|
-
if metadata:
|
|
456
|
-
config["metadata"] = metadata
|
|
457
|
-
if run_name:
|
|
458
|
-
config["run_name"] = run_name
|
|
459
|
-
return await self.ainvoke(query, config, **kwargs)
|