langchain-core 1.0.0a8__py3-none-any.whl → 1.0.0rc1__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.

Potentially problematic release.


This version of langchain-core might be problematic. Click here for more details.

Files changed (135) hide show
  1. langchain_core/__init__.py +1 -1
  2. langchain_core/_api/__init__.py +0 -1
  3. langchain_core/_api/beta_decorator.py +17 -20
  4. langchain_core/_api/deprecation.py +30 -35
  5. langchain_core/_import_utils.py +1 -1
  6. langchain_core/agents.py +7 -6
  7. langchain_core/caches.py +4 -10
  8. langchain_core/callbacks/__init__.py +1 -8
  9. langchain_core/callbacks/base.py +232 -243
  10. langchain_core/callbacks/file.py +33 -33
  11. langchain_core/callbacks/manager.py +353 -416
  12. langchain_core/callbacks/stdout.py +21 -22
  13. langchain_core/callbacks/streaming_stdout.py +32 -32
  14. langchain_core/callbacks/usage.py +54 -51
  15. langchain_core/chat_history.py +42 -57
  16. langchain_core/document_loaders/langsmith.py +21 -21
  17. langchain_core/documents/__init__.py +0 -1
  18. langchain_core/documents/base.py +37 -40
  19. langchain_core/documents/transformers.py +28 -29
  20. langchain_core/embeddings/fake.py +46 -52
  21. langchain_core/exceptions.py +5 -5
  22. langchain_core/indexing/api.py +11 -11
  23. langchain_core/indexing/base.py +24 -24
  24. langchain_core/language_models/__init__.py +0 -2
  25. langchain_core/language_models/_utils.py +51 -53
  26. langchain_core/language_models/base.py +23 -24
  27. langchain_core/language_models/chat_models.py +121 -144
  28. langchain_core/language_models/fake_chat_models.py +5 -5
  29. langchain_core/language_models/llms.py +10 -12
  30. langchain_core/load/dump.py +1 -1
  31. langchain_core/load/load.py +16 -16
  32. langchain_core/load/serializable.py +35 -34
  33. langchain_core/messages/__init__.py +1 -16
  34. langchain_core/messages/ai.py +105 -104
  35. langchain_core/messages/base.py +26 -26
  36. langchain_core/messages/block_translators/__init__.py +17 -17
  37. langchain_core/messages/block_translators/anthropic.py +2 -2
  38. langchain_core/messages/block_translators/bedrock_converse.py +2 -2
  39. langchain_core/messages/block_translators/google_genai.py +2 -2
  40. langchain_core/messages/block_translators/groq.py +117 -21
  41. langchain_core/messages/block_translators/langchain_v0.py +2 -2
  42. langchain_core/messages/block_translators/openai.py +4 -4
  43. langchain_core/messages/chat.py +1 -1
  44. langchain_core/messages/content.py +189 -193
  45. langchain_core/messages/function.py +5 -5
  46. langchain_core/messages/human.py +15 -17
  47. langchain_core/messages/modifier.py +1 -1
  48. langchain_core/messages/system.py +12 -14
  49. langchain_core/messages/tool.py +45 -49
  50. langchain_core/messages/utils.py +384 -396
  51. langchain_core/output_parsers/__init__.py +1 -14
  52. langchain_core/output_parsers/base.py +22 -23
  53. langchain_core/output_parsers/json.py +3 -3
  54. langchain_core/output_parsers/list.py +1 -1
  55. langchain_core/output_parsers/openai_functions.py +46 -44
  56. langchain_core/output_parsers/openai_tools.py +7 -7
  57. langchain_core/output_parsers/pydantic.py +10 -11
  58. langchain_core/output_parsers/string.py +1 -1
  59. langchain_core/output_parsers/transform.py +2 -2
  60. langchain_core/output_parsers/xml.py +1 -1
  61. langchain_core/outputs/__init__.py +1 -1
  62. langchain_core/outputs/chat_generation.py +14 -14
  63. langchain_core/outputs/generation.py +5 -5
  64. langchain_core/outputs/llm_result.py +5 -5
  65. langchain_core/prompt_values.py +5 -5
  66. langchain_core/prompts/__init__.py +3 -23
  67. langchain_core/prompts/base.py +32 -37
  68. langchain_core/prompts/chat.py +216 -222
  69. langchain_core/prompts/dict.py +2 -2
  70. langchain_core/prompts/few_shot.py +76 -83
  71. langchain_core/prompts/few_shot_with_templates.py +6 -8
  72. langchain_core/prompts/image.py +11 -13
  73. langchain_core/prompts/loading.py +1 -1
  74. langchain_core/prompts/message.py +2 -2
  75. langchain_core/prompts/prompt.py +14 -16
  76. langchain_core/prompts/string.py +19 -7
  77. langchain_core/prompts/structured.py +24 -25
  78. langchain_core/rate_limiters.py +36 -38
  79. langchain_core/retrievers.py +41 -182
  80. langchain_core/runnables/base.py +565 -590
  81. langchain_core/runnables/branch.py +7 -7
  82. langchain_core/runnables/config.py +37 -44
  83. langchain_core/runnables/configurable.py +8 -9
  84. langchain_core/runnables/fallbacks.py +8 -8
  85. langchain_core/runnables/graph.py +28 -27
  86. langchain_core/runnables/graph_ascii.py +19 -18
  87. langchain_core/runnables/graph_mermaid.py +20 -31
  88. langchain_core/runnables/graph_png.py +7 -7
  89. langchain_core/runnables/history.py +20 -20
  90. langchain_core/runnables/passthrough.py +8 -8
  91. langchain_core/runnables/retry.py +3 -3
  92. langchain_core/runnables/router.py +1 -1
  93. langchain_core/runnables/schema.py +33 -33
  94. langchain_core/runnables/utils.py +30 -34
  95. langchain_core/stores.py +72 -102
  96. langchain_core/sys_info.py +27 -29
  97. langchain_core/tools/__init__.py +1 -14
  98. langchain_core/tools/base.py +63 -63
  99. langchain_core/tools/convert.py +92 -92
  100. langchain_core/tools/render.py +9 -9
  101. langchain_core/tools/retriever.py +1 -1
  102. langchain_core/tools/simple.py +6 -7
  103. langchain_core/tools/structured.py +17 -18
  104. langchain_core/tracers/__init__.py +1 -9
  105. langchain_core/tracers/base.py +35 -35
  106. langchain_core/tracers/context.py +12 -17
  107. langchain_core/tracers/event_stream.py +3 -3
  108. langchain_core/tracers/langchain.py +8 -8
  109. langchain_core/tracers/log_stream.py +17 -18
  110. langchain_core/tracers/memory_stream.py +2 -2
  111. langchain_core/tracers/schemas.py +0 -129
  112. langchain_core/utils/aiter.py +31 -31
  113. langchain_core/utils/env.py +5 -5
  114. langchain_core/utils/function_calling.py +48 -120
  115. langchain_core/utils/html.py +4 -4
  116. langchain_core/utils/input.py +2 -2
  117. langchain_core/utils/interactive_env.py +1 -1
  118. langchain_core/utils/iter.py +19 -19
  119. langchain_core/utils/json.py +1 -1
  120. langchain_core/utils/json_schema.py +2 -2
  121. langchain_core/utils/mustache.py +5 -5
  122. langchain_core/utils/pydantic.py +17 -17
  123. langchain_core/utils/strings.py +4 -4
  124. langchain_core/utils/utils.py +25 -28
  125. langchain_core/vectorstores/base.py +43 -64
  126. langchain_core/vectorstores/in_memory.py +83 -85
  127. langchain_core/version.py +1 -1
  128. {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc1.dist-info}/METADATA +23 -11
  129. langchain_core-1.0.0rc1.dist-info/RECORD +172 -0
  130. langchain_core/memory.py +0 -120
  131. langchain_core/pydantic_v1/__init__.py +0 -30
  132. langchain_core/pydantic_v1/dataclasses.py +0 -23
  133. langchain_core/pydantic_v1/main.py +0 -23
  134. langchain_core-1.0.0a8.dist-info/RECORD +0 -176
  135. {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc1.dist-info}/WHEEL +0 -0
@@ -78,7 +78,7 @@ def is_pydantic_v1_subclass(cls: type) -> bool:
78
78
  """Check if the given class is Pydantic v1-like.
79
79
 
80
80
  Returns:
81
- True if the given class is a subclass of Pydantic ``BaseModel`` 1.x.
81
+ `True` if the given class is a subclass of Pydantic `BaseModel` 1.x.
82
82
  """
83
83
  return issubclass(cls, BaseModelV1)
84
84
 
@@ -87,7 +87,7 @@ def is_pydantic_v2_subclass(cls: type) -> bool:
87
87
  """Check if the given class is Pydantic v2-like.
88
88
 
89
89
  Returns:
90
- True if the given class is a subclass of Pydantic BaseModel 2.x.
90
+ `True` if the given class is a subclass of Pydantic BaseModel 2.x.
91
91
  """
92
92
  return issubclass(cls, BaseModel)
93
93
 
@@ -101,7 +101,7 @@ def is_basemodel_subclass(cls: type) -> bool:
101
101
  * pydantic.v1.BaseModel in Pydantic 2.x
102
102
 
103
103
  Returns:
104
- True if the given class is a subclass of Pydantic ``BaseModel``.
104
+ `True` if the given class is a subclass of Pydantic `BaseModel`.
105
105
  """
106
106
  # Before we can use issubclass on the cls we need to check if it is a class
107
107
  if not inspect.isclass(cls) or isinstance(cls, GenericAlias):
@@ -119,7 +119,7 @@ def is_basemodel_instance(obj: Any) -> bool:
119
119
  * pydantic.v1.BaseModel in Pydantic 2.x
120
120
 
121
121
  Returns:
122
- True if the given class is an instance of Pydantic ``BaseModel``.
122
+ `True` if the given class is an instance of Pydantic `BaseModel`.
123
123
  """
124
124
  return isinstance(obj, (BaseModel, BaseModelV1))
125
125
 
@@ -129,10 +129,10 @@ def pre_init(func: Callable) -> Any:
129
129
  """Decorator to run a function before model initialization.
130
130
 
131
131
  Args:
132
- func (Callable): The function to run before model initialization.
132
+ func: The function to run before model initialization.
133
133
 
134
134
  Returns:
135
- Any: The decorated function.
135
+ The decorated function.
136
136
  """
137
137
  with warnings.catch_warnings():
138
138
  warnings.filterwarnings(action="ignore", category=PydanticDeprecationWarning)
@@ -146,11 +146,11 @@ def pre_init(func: Callable) -> Any:
146
146
  """Decorator to run a function before model initialization.
147
147
 
148
148
  Args:
149
- cls (Type[BaseModel]): The model class.
150
- values (dict[str, Any]): The values to initialize the model with.
149
+ cls: The model class.
150
+ values: The values to initialize the model with.
151
151
 
152
152
  Returns:
153
- dict[str, Any]: The values to initialize the model with.
153
+ The values to initialize the model with.
154
154
  """
155
155
  # Insert default values
156
156
  fields = cls.model_fields
@@ -206,7 +206,7 @@ def _create_subset_model_v1(
206
206
  descriptions: dict | None = None,
207
207
  fn_description: str | None = None,
208
208
  ) -> type[BaseModel]:
209
- """Create a pydantic model with only a subset of model's fields."""
209
+ """Create a Pydantic model with only a subset of model's fields."""
210
210
  fields = {}
211
211
 
212
212
  for field_name in field_names:
@@ -235,7 +235,7 @@ def _create_subset_model_v2(
235
235
  descriptions: dict | None = None,
236
236
  fn_description: str | None = None,
237
237
  ) -> type[BaseModel]:
238
- """Create a pydantic model with a subset of the model fields."""
238
+ """Create a Pydantic model with a subset of the model fields."""
239
239
  descriptions_ = descriptions or {}
240
240
  fields = {}
241
241
  for field_name in field_names:
@@ -438,9 +438,9 @@ def create_model(
438
438
  /,
439
439
  **field_definitions: Any,
440
440
  ) -> type[BaseModel]:
441
- """Create a pydantic model with the given field definitions.
441
+ """Create a Pydantic model with the given field definitions.
442
442
 
443
- Please use create_model_v2 instead of this function.
443
+ Please use `create_model_v2` instead of this function.
444
444
 
445
445
  Args:
446
446
  model_name: The name of the model.
@@ -449,7 +449,7 @@ def create_model(
449
449
  **field_definitions: The field definitions for the model.
450
450
 
451
451
  Returns:
452
- Type[BaseModel]: The created model.
452
+ The created model.
453
453
  """
454
454
  kwargs = {}
455
455
  if "__root__" in field_definitions:
@@ -511,7 +511,7 @@ def create_model_v2(
511
511
  field_definitions: dict[str, Any] | None = None,
512
512
  root: Any | None = None,
513
513
  ) -> type[BaseModel]:
514
- """Create a pydantic model with the given field definitions.
514
+ """Create a Pydantic model with the given field definitions.
515
515
 
516
516
  Attention:
517
517
  Please do not use outside of langchain packages. This API
@@ -522,10 +522,10 @@ def create_model_v2(
522
522
  module_name: The name of the module where the model is defined.
523
523
  This is used by Pydantic to resolve any forward references.
524
524
  field_definitions: The field definitions for the model.
525
- root: Type for a root model (RootModel)
525
+ root: Type for a root model (`RootModel`)
526
526
 
527
527
  Returns:
528
- Type[BaseModel]: The created model.
528
+ The created model.
529
529
  """
530
530
  field_definitions = field_definitions or {}
531
531
 
@@ -10,7 +10,7 @@ def stringify_value(val: Any) -> str:
10
10
  val: The value to stringify.
11
11
 
12
12
  Returns:
13
- str: The stringified value.
13
+ The stringified value.
14
14
  """
15
15
  if isinstance(val, str):
16
16
  return val
@@ -28,7 +28,7 @@ def stringify_dict(data: dict) -> str:
28
28
  data: The dictionary to stringify.
29
29
 
30
30
  Returns:
31
- str: The stringified dictionary.
31
+ The stringified dictionary.
32
32
  """
33
33
  text = ""
34
34
  for key, value in data.items():
@@ -43,7 +43,7 @@ def comma_list(items: list[Any]) -> str:
43
43
  items: The list to convert.
44
44
 
45
45
  Returns:
46
- str: The comma-separated string.
46
+ The comma-separated string.
47
47
  """
48
48
  return ", ".join(str(item) for item in items)
49
49
 
@@ -60,7 +60,7 @@ def sanitize_for_postgres(text: str, replacement: str = "") -> str:
60
60
  replacement: String to replace NUL bytes with. Defaults to empty string.
61
61
 
62
62
  Returns:
63
- str: The sanitized text with NUL bytes removed or replaced.
63
+ The sanitized text with NUL bytes removed or replaced.
64
64
 
65
65
  Example:
66
66
  >>> sanitize_for_postgres("Hello\\x00world")
@@ -25,11 +25,11 @@ def xor_args(*arg_groups: tuple[str, ...]) -> Callable:
25
25
  """Validate specified keyword args are mutually exclusive.
26
26
 
27
27
  Args:
28
- *arg_groups (tuple[str, ...]): Groups of mutually exclusive keyword args.
28
+ *arg_groups: Groups of mutually exclusive keyword args.
29
29
 
30
30
  Returns:
31
- Callable: Decorator that validates the specified keyword args
32
- are mutually exclusive.
31
+ Decorator that validates the specified keyword args
32
+ are mutually exclusive.
33
33
  """
34
34
 
35
35
  def decorator(func: Callable) -> Callable:
@@ -60,7 +60,7 @@ def raise_for_status_with_text(response: Response) -> None:
60
60
  """Raise an error with the response text.
61
61
 
62
62
  Args:
63
- response (Response): The response to check for errors.
63
+ response: The response to check for errors.
64
64
 
65
65
  Raises:
66
66
  ValueError: If the response has an error status code.
@@ -79,11 +79,13 @@ def mock_now(dt_value: datetime.datetime) -> Iterator[type]:
79
79
  dt_value: The datetime value to use for datetime.now().
80
80
 
81
81
  Yields:
82
- datetime.datetime: The mocked datetime class.
82
+ The mocked datetime class.
83
83
 
84
84
  Example:
85
- with mock_now(datetime.datetime(2011, 2, 3, 10, 11)):
86
- assert datetime.datetime.now() == datetime.datetime(2011, 2, 3, 10, 11)
85
+ ```python
86
+ with mock_now(datetime.datetime(2011, 2, 3, 10, 11)):
87
+ assert datetime.datetime.now() == datetime.datetime(2011, 2, 3, 10, 11)
88
+ ```
87
89
  """
88
90
 
89
91
  class MockDateTime(datetime.datetime):
@@ -120,14 +122,12 @@ def guard_import(
120
122
  Raise an exception if the module is not installed.
121
123
 
122
124
  Args:
123
- module_name (str): The name of the module to import.
124
- pip_name (str, optional): The name of the module to install with pip.
125
- Defaults to None.
126
- package (str, optional): The package to import the module from.
127
- Defaults to None.
125
+ module_name: The name of the module to import.
126
+ pip_name: The name of the module to install with pip.
127
+ package: The package to import the module from.
128
128
 
129
129
  Returns:
130
- Any: The imported module.
130
+ The imported module.
131
131
 
132
132
  Raises:
133
133
  ImportError: If the module is not installed.
@@ -154,15 +154,12 @@ def check_package_version(
154
154
  """Check the version of a package.
155
155
 
156
156
  Args:
157
- package (str): The name of the package.
158
- lt_version (str, optional): The version must be less than this.
159
- Defaults to None.
160
- lte_version (str, optional): The version must be less than or equal to this.
161
- Defaults to None.
162
- gt_version (str, optional): The version must be greater than this.
163
- Defaults to None.
164
- gte_version (str, optional): The version must be greater than or equal to this.
165
- Defaults to None.
157
+ package: The name of the package.
158
+ lt_version: The version must be less than this.
159
+ lte_version: The version must be less than or equal to this.
160
+ gt_version: The version must be greater than this.
161
+ gte_version: The version must be greater than or equal to this.
162
+
166
163
 
167
164
  Raises:
168
165
  ValueError: If the package version does not meet the requirements.
@@ -201,7 +198,7 @@ def get_pydantic_field_names(pydantic_cls: Any) -> set[str]:
201
198
  pydantic_cls: Pydantic class.
202
199
 
203
200
  Returns:
204
- set[str]: Field names.
201
+ Field names.
205
202
  """
206
203
  all_required_field_names = set()
207
204
  if is_pydantic_v1_subclass(pydantic_cls):
@@ -228,7 +225,7 @@ def _build_model_kwargs(
228
225
  all_required_field_names: All required field names for the pydantic class.
229
226
 
230
227
  Returns:
231
- dict[str, Any]: Extra kwargs.
228
+ Extra kwargs.
232
229
 
233
230
  Raises:
234
231
  ValueError: If a field is specified in both values and extra_kwargs.
@@ -276,7 +273,7 @@ def build_extra_kwargs(
276
273
  all_required_field_names: All required field names for the pydantic class.
277
274
 
278
275
  Returns:
279
- dict[str, Any]: Extra kwargs.
276
+ Extra kwargs.
280
277
 
281
278
  Raises:
282
279
  ValueError: If a field is specified in both values and extra_kwargs.
@@ -310,10 +307,10 @@ def convert_to_secret_str(value: SecretStr | str) -> SecretStr:
310
307
  """Convert a string to a SecretStr if needed.
311
308
 
312
309
  Args:
313
- value (Union[SecretStr, str]): The value to convert.
310
+ value: The value to convert.
314
311
 
315
312
  Returns:
316
- SecretStr: The SecretStr value.
313
+ The SecretStr value.
317
314
  """
318
315
  if isinstance(value, SecretStr):
319
316
  return value
@@ -501,7 +498,7 @@ Used for:
501
498
  def ensure_id(id_val: str | None) -> str:
502
499
  """Ensure the ID is a valid string, generating a new UUID if not provided.
503
500
 
504
- Auto-generated UUIDs are prefixed by ``'lc_'`` to indicate they are
501
+ Auto-generated UUIDs are prefixed by `'lc_'` to indicate they are
505
502
  LangChain-generated IDs.
506
503
 
507
504
  Args:
@@ -3,21 +3,7 @@
3
3
  One of the most common ways to store and search over unstructured data is to
4
4
  embed it and store the resulting embedding vectors, and then query the store
5
5
  and retrieve the data that are 'most similar' to the embedded query.
6
-
7
- **Class hierarchy:**
8
-
9
- .. code-block::
10
-
11
- VectorStore --> <name> # Examples: Annoy, FAISS, Milvus
12
-
13
- BaseRetriever --> VectorStoreRetriever --> <name>Retriever # Example: VespaRetriever
14
-
15
- **Main helpers:**
16
-
17
- .. code-block::
18
-
19
- Embeddings, Document
20
- """ # noqa: E501
6
+ """
21
7
 
22
8
  from __future__ import annotations
23
9
 
@@ -123,12 +109,11 @@ class VectorStore(ABC):
123
109
  """Delete by vector ID or other criteria.
124
110
 
125
111
  Args:
126
- ids: List of ids to delete. If None, delete all. Default is None.
112
+ ids: List of ids to delete. If `None`, delete all. Default is None.
127
113
  **kwargs: Other keyword arguments that subclasses might use.
128
114
 
129
115
  Returns:
130
- Optional[bool]: True if deletion is successful,
131
- False otherwise, None if not implemented.
116
+ True if deletion is successful, False otherwise, None if not implemented.
132
117
  """
133
118
  msg = "delete method must be implemented by subclass."
134
119
  raise NotImplementedError(msg)
@@ -191,12 +176,11 @@ class VectorStore(ABC):
191
176
  """Async delete by vector ID or other criteria.
192
177
 
193
178
  Args:
194
- ids: List of ids to delete. If None, delete all. Default is None.
179
+ ids: List of ids to delete. If `None`, delete all. Default is None.
195
180
  **kwargs: Other keyword arguments that subclasses might use.
196
181
 
197
182
  Returns:
198
- Optional[bool]: True if deletion is successful,
199
- False otherwise, None if not implemented.
183
+ True if deletion is successful, False otherwise, None if not implemented.
200
184
  """
201
185
  return await run_in_executor(None, self.delete, ids, **kwargs)
202
186
 
@@ -255,7 +239,7 @@ class VectorStore(ABC):
255
239
 
256
240
  Args:
257
241
  documents: Documents to add to the vectorstore.
258
- kwargs: Additional keyword arguments.
242
+ **kwargs: Additional keyword arguments.
259
243
  if kwargs contains ids and documents contain ids,
260
244
  the ids in the kwargs will receive precedence.
261
245
 
@@ -287,7 +271,7 @@ class VectorStore(ABC):
287
271
 
288
272
  Args:
289
273
  documents: Documents to add to the vectorstore.
290
- kwargs: Additional keyword arguments.
274
+ **kwargs: Additional keyword arguments.
291
275
 
292
276
  Returns:
293
277
  List of IDs of the added texts.
@@ -815,10 +799,10 @@ class VectorStore(ABC):
815
799
  Args:
816
800
  documents: List of Documents to add to the vectorstore.
817
801
  embedding: Embedding function to use.
818
- kwargs: Additional keyword arguments.
802
+ **kwargs: Additional keyword arguments.
819
803
 
820
804
  Returns:
821
- VectorStore: VectorStore initialized from documents and embeddings.
805
+ VectorStore initialized from documents and embeddings.
822
806
  """
823
807
  texts = [d.page_content for d in documents]
824
808
  metadatas = [d.metadata for d in documents]
@@ -845,10 +829,10 @@ class VectorStore(ABC):
845
829
  Args:
846
830
  documents: List of Documents to add to the vectorstore.
847
831
  embedding: Embedding function to use.
848
- kwargs: Additional keyword arguments.
832
+ **kwargs: Additional keyword arguments.
849
833
 
850
834
  Returns:
851
- VectorStore: VectorStore initialized from documents and embeddings.
835
+ VectorStore initialized from documents and embeddings.
852
836
  """
853
837
  texts = [d.page_content for d in documents]
854
838
  metadatas = [d.metadata for d in documents]
@@ -882,10 +866,10 @@ class VectorStore(ABC):
882
866
  metadatas: Optional list of metadatas associated with the texts.
883
867
  Default is None.
884
868
  ids: Optional list of IDs associated with the texts.
885
- kwargs: Additional keyword arguments.
869
+ **kwargs: Additional keyword arguments.
886
870
 
887
871
  Returns:
888
- VectorStore: VectorStore initialized from texts and embeddings.
872
+ VectorStore initialized from texts and embeddings.
889
873
  """
890
874
 
891
875
  @classmethod
@@ -906,10 +890,10 @@ class VectorStore(ABC):
906
890
  metadatas: Optional list of metadatas associated with the texts.
907
891
  Default is None.
908
892
  ids: Optional list of IDs associated with the texts.
909
- kwargs: Additional keyword arguments.
893
+ **kwargs: Additional keyword arguments.
910
894
 
911
895
  Returns:
912
- VectorStore: VectorStore initialized from texts and embeddings.
896
+ VectorStore initialized from texts and embeddings.
913
897
  """
914
898
  if ids is not None:
915
899
  kwargs["ids"] = ids
@@ -930,12 +914,11 @@ class VectorStore(ABC):
930
914
  Args:
931
915
  **kwargs: Keyword arguments to pass to the search function.
932
916
  Can include:
933
- search_type (Optional[str]): Defines the type of search that
934
- the Retriever should perform.
935
- Can be "similarity" (default), "mmr", or
917
+ search_type: Defines the type of search that the Retriever should
918
+ perform. Can be "similarity" (default), "mmr", or
936
919
  "similarity_score_threshold".
937
- search_kwargs (Optional[Dict]): Keyword arguments to pass to the
938
- search function. Can include things like:
920
+ search_kwargs: Keyword arguments to pass to the search function. Can
921
+ include things like:
939
922
  k: Amount of documents to return (Default: 4)
940
923
  score_threshold: Minimum relevance threshold
941
924
  for similarity_score_threshold
@@ -946,39 +929,35 @@ class VectorStore(ABC):
946
929
  filter: Filter by document metadata
947
930
 
948
931
  Returns:
949
- VectorStoreRetriever: Retriever class for VectorStore.
932
+ Retriever class for VectorStore.
950
933
 
951
934
  Examples:
935
+ ```python
936
+ # Retrieve more documents with higher diversity
937
+ # Useful if your dataset has many similar documents
938
+ docsearch.as_retriever(
939
+ search_type="mmr", search_kwargs={"k": 6, "lambda_mult": 0.25}
940
+ )
952
941
 
953
- .. code-block:: python
954
-
955
- # Retrieve more documents with higher diversity
956
- # Useful if your dataset has many similar documents
957
- docsearch.as_retriever(
958
- search_type="mmr", search_kwargs={"k": 6, "lambda_mult": 0.25}
959
- )
960
-
961
- # Fetch more documents for the MMR algorithm to consider
962
- # But only return the top 5
963
- docsearch.as_retriever(
964
- search_type="mmr", search_kwargs={"k": 5, "fetch_k": 50}
965
- )
966
-
967
- # Only retrieve documents that have a relevance score
968
- # Above a certain threshold
969
- docsearch.as_retriever(
970
- search_type="similarity_score_threshold",
971
- search_kwargs={"score_threshold": 0.8},
972
- )
942
+ # Fetch more documents for the MMR algorithm to consider
943
+ # But only return the top 5
944
+ docsearch.as_retriever(search_type="mmr", search_kwargs={"k": 5, "fetch_k": 50})
973
945
 
974
- # Only get the single most similar document from the dataset
975
- docsearch.as_retriever(search_kwargs={"k": 1})
946
+ # Only retrieve documents that have a relevance score
947
+ # Above a certain threshold
948
+ docsearch.as_retriever(
949
+ search_type="similarity_score_threshold",
950
+ search_kwargs={"score_threshold": 0.8},
951
+ )
976
952
 
977
- # Use a filter to only retrieve documents from a specific paper
978
- docsearch.as_retriever(
979
- search_kwargs={"filter": {"paper_title": "GPT-4 Technical Report"}}
980
- )
953
+ # Only get the single most similar document from the dataset
954
+ docsearch.as_retriever(search_kwargs={"k": 1})
981
955
 
956
+ # Use a filter to only retrieve documents from a specific paper
957
+ docsearch.as_retriever(
958
+ search_kwargs={"filter": {"paper_title": "GPT-4 Technical Report"}}
959
+ )
960
+ ```
982
961
  """
983
962
  tags = kwargs.pop("tags", None) or [*self._get_retriever_tags()]
984
963
  return VectorStoreRetriever(vectorstore=self, tags=tags, **kwargs)
@@ -1012,7 +991,7 @@ class VectorStoreRetriever(BaseRetriever):
1012
991
  values: Values to validate.
1013
992
 
1014
993
  Returns:
1015
- Values: Validated values.
994
+ Validated values.
1016
995
 
1017
996
  Raises:
1018
997
  ValueError: If search_type is not one of the allowed search types.