langchain-core 0.4.0.dev0__py3-none-any.whl → 1.0.0__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 (172) hide show
  1. langchain_core/__init__.py +1 -1
  2. langchain_core/_api/__init__.py +3 -4
  3. langchain_core/_api/beta_decorator.py +45 -70
  4. langchain_core/_api/deprecation.py +80 -80
  5. langchain_core/_api/path.py +22 -8
  6. langchain_core/_import_utils.py +10 -4
  7. langchain_core/agents.py +25 -21
  8. langchain_core/caches.py +53 -63
  9. langchain_core/callbacks/__init__.py +1 -8
  10. langchain_core/callbacks/base.py +341 -348
  11. langchain_core/callbacks/file.py +55 -44
  12. langchain_core/callbacks/manager.py +546 -683
  13. langchain_core/callbacks/stdout.py +29 -30
  14. langchain_core/callbacks/streaming_stdout.py +35 -36
  15. langchain_core/callbacks/usage.py +65 -70
  16. langchain_core/chat_history.py +48 -55
  17. langchain_core/document_loaders/base.py +46 -21
  18. langchain_core/document_loaders/langsmith.py +39 -36
  19. langchain_core/documents/__init__.py +0 -1
  20. langchain_core/documents/base.py +96 -74
  21. langchain_core/documents/compressor.py +12 -9
  22. langchain_core/documents/transformers.py +29 -28
  23. langchain_core/embeddings/fake.py +56 -57
  24. langchain_core/env.py +2 -3
  25. langchain_core/example_selectors/base.py +12 -0
  26. langchain_core/example_selectors/length_based.py +1 -1
  27. langchain_core/example_selectors/semantic_similarity.py +21 -25
  28. langchain_core/exceptions.py +15 -9
  29. langchain_core/globals.py +4 -163
  30. langchain_core/indexing/api.py +132 -125
  31. langchain_core/indexing/base.py +64 -67
  32. langchain_core/indexing/in_memory.py +26 -6
  33. langchain_core/language_models/__init__.py +15 -27
  34. langchain_core/language_models/_utils.py +267 -117
  35. langchain_core/language_models/base.py +92 -177
  36. langchain_core/language_models/chat_models.py +547 -407
  37. langchain_core/language_models/fake.py +11 -11
  38. langchain_core/language_models/fake_chat_models.py +72 -118
  39. langchain_core/language_models/llms.py +168 -242
  40. langchain_core/load/dump.py +8 -11
  41. langchain_core/load/load.py +32 -28
  42. langchain_core/load/mapping.py +2 -4
  43. langchain_core/load/serializable.py +50 -56
  44. langchain_core/messages/__init__.py +36 -51
  45. langchain_core/messages/ai.py +377 -150
  46. langchain_core/messages/base.py +239 -47
  47. langchain_core/messages/block_translators/__init__.py +111 -0
  48. langchain_core/messages/block_translators/anthropic.py +470 -0
  49. langchain_core/messages/block_translators/bedrock.py +94 -0
  50. langchain_core/messages/block_translators/bedrock_converse.py +297 -0
  51. langchain_core/messages/block_translators/google_genai.py +530 -0
  52. langchain_core/messages/block_translators/google_vertexai.py +21 -0
  53. langchain_core/messages/block_translators/groq.py +143 -0
  54. langchain_core/messages/block_translators/langchain_v0.py +301 -0
  55. langchain_core/messages/block_translators/openai.py +1010 -0
  56. langchain_core/messages/chat.py +2 -3
  57. langchain_core/messages/content.py +1423 -0
  58. langchain_core/messages/function.py +7 -7
  59. langchain_core/messages/human.py +44 -38
  60. langchain_core/messages/modifier.py +3 -2
  61. langchain_core/messages/system.py +40 -27
  62. langchain_core/messages/tool.py +160 -58
  63. langchain_core/messages/utils.py +527 -638
  64. langchain_core/output_parsers/__init__.py +1 -14
  65. langchain_core/output_parsers/base.py +68 -104
  66. langchain_core/output_parsers/json.py +13 -17
  67. langchain_core/output_parsers/list.py +11 -33
  68. langchain_core/output_parsers/openai_functions.py +56 -74
  69. langchain_core/output_parsers/openai_tools.py +68 -109
  70. langchain_core/output_parsers/pydantic.py +15 -13
  71. langchain_core/output_parsers/string.py +6 -2
  72. langchain_core/output_parsers/transform.py +17 -60
  73. langchain_core/output_parsers/xml.py +34 -44
  74. langchain_core/outputs/__init__.py +1 -1
  75. langchain_core/outputs/chat_generation.py +26 -11
  76. langchain_core/outputs/chat_result.py +1 -3
  77. langchain_core/outputs/generation.py +17 -6
  78. langchain_core/outputs/llm_result.py +15 -8
  79. langchain_core/prompt_values.py +29 -123
  80. langchain_core/prompts/__init__.py +3 -27
  81. langchain_core/prompts/base.py +48 -63
  82. langchain_core/prompts/chat.py +259 -288
  83. langchain_core/prompts/dict.py +19 -11
  84. langchain_core/prompts/few_shot.py +84 -90
  85. langchain_core/prompts/few_shot_with_templates.py +14 -12
  86. langchain_core/prompts/image.py +19 -14
  87. langchain_core/prompts/loading.py +6 -8
  88. langchain_core/prompts/message.py +7 -8
  89. langchain_core/prompts/prompt.py +42 -43
  90. langchain_core/prompts/string.py +37 -16
  91. langchain_core/prompts/structured.py +43 -46
  92. langchain_core/rate_limiters.py +51 -60
  93. langchain_core/retrievers.py +52 -192
  94. langchain_core/runnables/base.py +1727 -1683
  95. langchain_core/runnables/branch.py +52 -73
  96. langchain_core/runnables/config.py +89 -103
  97. langchain_core/runnables/configurable.py +128 -130
  98. langchain_core/runnables/fallbacks.py +93 -82
  99. langchain_core/runnables/graph.py +127 -127
  100. langchain_core/runnables/graph_ascii.py +63 -41
  101. langchain_core/runnables/graph_mermaid.py +87 -70
  102. langchain_core/runnables/graph_png.py +31 -36
  103. langchain_core/runnables/history.py +145 -161
  104. langchain_core/runnables/passthrough.py +141 -144
  105. langchain_core/runnables/retry.py +84 -68
  106. langchain_core/runnables/router.py +33 -37
  107. langchain_core/runnables/schema.py +79 -72
  108. langchain_core/runnables/utils.py +95 -139
  109. langchain_core/stores.py +85 -131
  110. langchain_core/structured_query.py +11 -15
  111. langchain_core/sys_info.py +31 -32
  112. langchain_core/tools/__init__.py +1 -14
  113. langchain_core/tools/base.py +221 -247
  114. langchain_core/tools/convert.py +144 -161
  115. langchain_core/tools/render.py +10 -10
  116. langchain_core/tools/retriever.py +12 -19
  117. langchain_core/tools/simple.py +52 -29
  118. langchain_core/tools/structured.py +56 -60
  119. langchain_core/tracers/__init__.py +1 -9
  120. langchain_core/tracers/_streaming.py +6 -7
  121. langchain_core/tracers/base.py +103 -112
  122. langchain_core/tracers/context.py +29 -48
  123. langchain_core/tracers/core.py +142 -105
  124. langchain_core/tracers/evaluation.py +30 -34
  125. langchain_core/tracers/event_stream.py +162 -117
  126. langchain_core/tracers/langchain.py +34 -36
  127. langchain_core/tracers/log_stream.py +87 -49
  128. langchain_core/tracers/memory_stream.py +3 -3
  129. langchain_core/tracers/root_listeners.py +18 -34
  130. langchain_core/tracers/run_collector.py +8 -20
  131. langchain_core/tracers/schemas.py +0 -125
  132. langchain_core/tracers/stdout.py +3 -3
  133. langchain_core/utils/__init__.py +1 -4
  134. langchain_core/utils/_merge.py +47 -9
  135. langchain_core/utils/aiter.py +70 -66
  136. langchain_core/utils/env.py +12 -9
  137. langchain_core/utils/function_calling.py +139 -206
  138. langchain_core/utils/html.py +7 -8
  139. langchain_core/utils/input.py +6 -6
  140. langchain_core/utils/interactive_env.py +6 -2
  141. langchain_core/utils/iter.py +48 -45
  142. langchain_core/utils/json.py +14 -4
  143. langchain_core/utils/json_schema.py +159 -43
  144. langchain_core/utils/mustache.py +32 -25
  145. langchain_core/utils/pydantic.py +67 -40
  146. langchain_core/utils/strings.py +5 -5
  147. langchain_core/utils/usage.py +1 -1
  148. langchain_core/utils/utils.py +104 -62
  149. langchain_core/vectorstores/base.py +131 -179
  150. langchain_core/vectorstores/in_memory.py +113 -182
  151. langchain_core/vectorstores/utils.py +23 -17
  152. langchain_core/version.py +1 -1
  153. langchain_core-1.0.0.dist-info/METADATA +68 -0
  154. langchain_core-1.0.0.dist-info/RECORD +172 -0
  155. {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
  156. langchain_core/beta/__init__.py +0 -1
  157. langchain_core/beta/runnables/__init__.py +0 -1
  158. langchain_core/beta/runnables/context.py +0 -448
  159. langchain_core/memory.py +0 -116
  160. langchain_core/messages/content_blocks.py +0 -1435
  161. langchain_core/prompts/pipeline.py +0 -133
  162. langchain_core/pydantic_v1/__init__.py +0 -30
  163. langchain_core/pydantic_v1/dataclasses.py +0 -23
  164. langchain_core/pydantic_v1/main.py +0 -23
  165. langchain_core/tracers/langchain_v1.py +0 -23
  166. langchain_core/utils/loading.py +0 -31
  167. langchain_core/v1/__init__.py +0 -1
  168. langchain_core/v1/chat_models.py +0 -1047
  169. langchain_core/v1/messages.py +0 -755
  170. langchain_core-0.4.0.dev0.dist-info/METADATA +0 -108
  171. langchain_core-0.4.0.dev0.dist-info/RECORD +0 -177
  172. langchain_core-0.4.0.dev0.dist-info/entry_points.txt +0 -4
@@ -5,7 +5,9 @@ from __future__ import annotations
5
5
  import abc
6
6
  import time
7
7
  from abc import ABC, abstractmethod
8
- from typing import TYPE_CHECKING, Any, Optional, TypedDict
8
+ from typing import TYPE_CHECKING, Any, TypedDict
9
+
10
+ from typing_extensions import override
9
11
 
10
12
  from langchain_core._api import beta
11
13
  from langchain_core.retrievers import BaseRetriever
@@ -59,7 +61,7 @@ class RecordManager(ABC):
59
61
  """Initialize the record manager.
60
62
 
61
63
  Args:
62
- namespace (str): The namespace for the record manager.
64
+ namespace: The namespace for the record manager.
63
65
  """
64
66
  self.namespace = namespace
65
67
 
@@ -98,8 +100,8 @@ class RecordManager(ABC):
98
100
  self,
99
101
  keys: Sequence[str],
100
102
  *,
101
- group_ids: Optional[Sequence[Optional[str]]] = None,
102
- time_at_least: Optional[float] = None,
103
+ group_ids: Sequence[str | None] | None = None,
104
+ time_at_least: float | None = None,
103
105
  ) -> None:
104
106
  """Upsert records into the database.
105
107
 
@@ -126,8 +128,8 @@ class RecordManager(ABC):
126
128
  self,
127
129
  keys: Sequence[str],
128
130
  *,
129
- group_ids: Optional[Sequence[Optional[str]]] = None,
130
- time_at_least: Optional[float] = None,
131
+ group_ids: Sequence[str | None] | None = None,
132
+ time_at_least: float | None = None,
131
133
  ) -> None:
132
134
  """Asynchronously upsert records into the database.
133
135
 
@@ -175,10 +177,10 @@ class RecordManager(ABC):
175
177
  def list_keys(
176
178
  self,
177
179
  *,
178
- before: Optional[float] = None,
179
- after: Optional[float] = None,
180
- group_ids: Optional[Sequence[str]] = None,
181
- limit: Optional[int] = None,
180
+ before: float | None = None,
181
+ after: float | None = None,
182
+ group_ids: Sequence[str] | None = None,
183
+ limit: int | None = None,
182
184
  ) -> list[str]:
183
185
  """List records in the database based on the provided filters.
184
186
 
@@ -196,10 +198,10 @@ class RecordManager(ABC):
196
198
  async def alist_keys(
197
199
  self,
198
200
  *,
199
- before: Optional[float] = None,
200
- after: Optional[float] = None,
201
- group_ids: Optional[Sequence[str]] = None,
202
- limit: Optional[int] = None,
201
+ before: float | None = None,
202
+ after: float | None = None,
203
+ group_ids: Sequence[str] | None = None,
204
+ limit: int | None = None,
203
205
  ) -> list[str]:
204
206
  """Asynchronously list records in the database based on the provided filters.
205
207
 
@@ -231,7 +233,7 @@ class RecordManager(ABC):
231
233
 
232
234
 
233
235
  class _Record(TypedDict):
234
- group_id: Optional[str]
236
+ group_id: str | None
235
237
  updated_at: float
236
238
 
237
239
 
@@ -242,7 +244,7 @@ class InMemoryRecordManager(RecordManager):
242
244
  """Initialize the in-memory record manager.
243
245
 
244
246
  Args:
245
- namespace (str): The namespace for the record manager.
247
+ namespace: The namespace for the record manager.
246
248
  """
247
249
  super().__init__(namespace)
248
250
  # Each key points to a dictionary
@@ -254,32 +256,32 @@ class InMemoryRecordManager(RecordManager):
254
256
  """In-memory schema creation is simply ensuring the structure is initialized."""
255
257
 
256
258
  async def acreate_schema(self) -> None:
257
- """Async in-memory schema creation is simply ensuring the structure is initialized.""" # noqa: E501
259
+ """In-memory schema creation is simply ensuring the structure is initialized."""
258
260
 
261
+ @override
259
262
  def get_time(self) -> float:
260
- """Get the current server time as a high resolution timestamp!"""
261
263
  return time.time()
262
264
 
265
+ @override
263
266
  async def aget_time(self) -> float:
264
- """Async get the current server time as a high resolution timestamp!"""
265
267
  return self.get_time()
266
268
 
267
269
  def update(
268
270
  self,
269
271
  keys: Sequence[str],
270
272
  *,
271
- group_ids: Optional[Sequence[Optional[str]]] = None,
272
- time_at_least: Optional[float] = None,
273
+ group_ids: Sequence[str | None] | None = None,
274
+ time_at_least: float | None = None,
273
275
  ) -> None:
274
276
  """Upsert records into the database.
275
277
 
276
278
  Args:
277
279
  keys: A list of record keys to upsert.
278
280
  group_ids: A list of group IDs corresponding to the keys.
279
- Defaults to None.
281
+
280
282
  time_at_least: Optional timestamp. Implementation can use this
281
283
  to optionally verify that the timestamp IS at least this time
282
- in the system that stores. Defaults to None.
284
+ in the system that stores.
283
285
  E.g., use to validate that the time in the postgres database
284
286
  is equal to or larger than the given timestamp, if not
285
287
  raise an error.
@@ -305,28 +307,23 @@ class InMemoryRecordManager(RecordManager):
305
307
  self,
306
308
  keys: Sequence[str],
307
309
  *,
308
- group_ids: Optional[Sequence[Optional[str]]] = None,
309
- time_at_least: Optional[float] = None,
310
+ group_ids: Sequence[str | None] | None = None,
311
+ time_at_least: float | None = None,
310
312
  ) -> None:
311
313
  """Async upsert records into the database.
312
314
 
313
315
  Args:
314
316
  keys: A list of record keys to upsert.
315
317
  group_ids: A list of group IDs corresponding to the keys.
316
- Defaults to None.
318
+
317
319
  time_at_least: Optional timestamp. Implementation can use this
318
320
  to optionally verify that the timestamp IS at least this time
319
- in the system that stores. Defaults to None.
321
+ in the system that stores.
320
322
  E.g., use to validate that the time in the postgres database
321
323
  is equal to or larger than the given timestamp, if not
322
324
  raise an error.
323
325
  This is meant to help prevent time-drift issues since
324
326
  time may not be monotonically increasing!
325
-
326
- Raises:
327
- ValueError: If the length of keys doesn't match the length of group
328
- ids.
329
- ValueError: If time_at_least is in the future.
330
327
  """
331
328
  self.update(keys, group_ids=group_ids, time_at_least=time_at_least)
332
329
 
@@ -355,22 +352,22 @@ class InMemoryRecordManager(RecordManager):
355
352
  def list_keys(
356
353
  self,
357
354
  *,
358
- before: Optional[float] = None,
359
- after: Optional[float] = None,
360
- group_ids: Optional[Sequence[str]] = None,
361
- limit: Optional[int] = None,
355
+ before: float | None = None,
356
+ after: float | None = None,
357
+ group_ids: Sequence[str] | None = None,
358
+ limit: int | None = None,
362
359
  ) -> list[str]:
363
360
  """List records in the database based on the provided filters.
364
361
 
365
362
  Args:
366
363
  before: Filter to list records updated before this time.
367
- Defaults to None.
364
+
368
365
  after: Filter to list records updated after this time.
369
- Defaults to None.
366
+
370
367
  group_ids: Filter to list records with specific group IDs.
371
- Defaults to None.
368
+
372
369
  limit: optional limit on the number of records to return.
373
- Defaults to None.
370
+
374
371
 
375
372
  Returns:
376
373
  A list of keys for the matching records.
@@ -391,22 +388,22 @@ class InMemoryRecordManager(RecordManager):
391
388
  async def alist_keys(
392
389
  self,
393
390
  *,
394
- before: Optional[float] = None,
395
- after: Optional[float] = None,
396
- group_ids: Optional[Sequence[str]] = None,
397
- limit: Optional[int] = None,
391
+ before: float | None = None,
392
+ after: float | None = None,
393
+ group_ids: Sequence[str] | None = None,
394
+ limit: int | None = None,
398
395
  ) -> list[str]:
399
396
  """Async list records in the database based on the provided filters.
400
397
 
401
398
  Args:
402
399
  before: Filter to list records updated before this time.
403
- Defaults to None.
400
+
404
401
  after: Filter to list records updated after this time.
405
- Defaults to None.
402
+
406
403
  group_ids: Filter to list records with specific group IDs.
407
- Defaults to None.
404
+
408
405
  limit: optional limit on the number of records to return.
409
- Defaults to None.
406
+
410
407
 
411
408
  Returns:
412
409
  A list of keys for the matching records.
@@ -488,8 +485,8 @@ class DeleteResponse(TypedDict, total=False):
488
485
  failed: Sequence[str]
489
486
  """The IDs that failed to be deleted.
490
487
 
491
- Please note that deleting an ID that
492
- does not exist is **NOT** considered a failure.
488
+ !!! warning
489
+ Deleting an ID that does not exist is **NOT** considered a failure.
493
490
  """
494
491
 
495
492
  num_failed: int
@@ -512,7 +509,7 @@ class DocumentIndex(BaseRetriever):
512
509
  2. Fetching document by ID.
513
510
  3. Searching for document using a query.
514
511
 
515
- .. versionadded:: 0.2.29
512
+ !!! version-added "Added in version 0.2.29"
516
513
  """
517
514
 
518
515
  @abc.abstractmethod
@@ -525,14 +522,14 @@ class DocumentIndex(BaseRetriever):
525
522
 
526
523
  When an ID is specified and the content already exists in the vectorstore,
527
524
  the upsert method should update the content with the new data. If the content
528
- does not exist, the upsert method should add the item to the vectorstore.
525
+ does not exist, the upsert method should add the item to the `VectorStore`.
529
526
 
530
527
  Args:
531
- items: Sequence of documents to add to the vectorstore.
528
+ items: Sequence of documents to add to the `VectorStore`.
532
529
  **kwargs: Additional keyword arguments.
533
530
 
534
531
  Returns:
535
- UpsertResponse: A response object that contains the list of IDs that were
532
+ A response object that contains the list of IDs that were
536
533
  successfully added or updated in the vectorstore and the list of IDs that
537
534
  failed to be added or updated.
538
535
  """
@@ -548,14 +545,14 @@ class DocumentIndex(BaseRetriever):
548
545
 
549
546
  When an ID is specified and the item already exists in the vectorstore,
550
547
  the upsert method should update the item with the new data. If the item
551
- does not exist, the upsert method should add the item to the vectorstore.
548
+ does not exist, the upsert method should add the item to the `VectorStore`.
552
549
 
553
550
  Args:
554
- items: Sequence of documents to add to the vectorstore.
551
+ items: Sequence of documents to add to the `VectorStore`.
555
552
  **kwargs: Additional keyword arguments.
556
553
 
557
554
  Returns:
558
- UpsertResponse: A response object that contains the list of IDs that were
555
+ A response object that contains the list of IDs that were
559
556
  successfully added or updated in the vectorstore and the list of IDs that
560
557
  failed to be added or updated.
561
558
  """
@@ -567,24 +564,24 @@ class DocumentIndex(BaseRetriever):
567
564
  )
568
565
 
569
566
  @abc.abstractmethod
570
- def delete(self, ids: Optional[list[str]] = None, **kwargs: Any) -> DeleteResponse:
567
+ def delete(self, ids: list[str] | None = None, **kwargs: Any) -> DeleteResponse:
571
568
  """Delete by IDs or other criteria.
572
569
 
573
570
  Calling delete without any input parameters should raise a ValueError!
574
571
 
575
572
  Args:
576
573
  ids: List of ids to delete.
577
- kwargs: Additional keyword arguments. This is up to the implementation.
574
+ **kwargs: Additional keyword arguments. This is up to the implementation.
578
575
  For example, can include an option to delete the entire index,
579
576
  or else issue a non-blocking delete etc.
580
577
 
581
578
  Returns:
582
- DeleteResponse: A response object that contains the list of IDs that were
579
+ A response object that contains the list of IDs that were
583
580
  successfully deleted and the list of IDs that failed to be deleted.
584
581
  """
585
582
 
586
583
  async def adelete(
587
- self, ids: Optional[list[str]] = None, **kwargs: Any
584
+ self, ids: list[str] | None = None, **kwargs: Any
588
585
  ) -> DeleteResponse:
589
586
  """Delete by IDs or other criteria. Async variant.
590
587
 
@@ -592,11 +589,11 @@ class DocumentIndex(BaseRetriever):
592
589
 
593
590
  Args:
594
591
  ids: List of ids to delete.
595
- kwargs: Additional keyword arguments. This is up to the implementation.
592
+ **kwargs: Additional keyword arguments. This is up to the implementation.
596
593
  For example, can include an option to delete the entire index.
597
594
 
598
595
  Returns:
599
- DeleteResponse: A response object that contains the list of IDs that were
596
+ A response object that contains the list of IDs that were
600
597
  successfully deleted and the list of IDs that failed to be deleted.
601
598
  """
602
599
  return await run_in_executor(
@@ -627,10 +624,10 @@ class DocumentIndex(BaseRetriever):
627
624
 
628
625
  Args:
629
626
  ids: List of IDs to get.
630
- kwargs: Additional keyword arguments. These are up to the implementation.
627
+ **kwargs: Additional keyword arguments. These are up to the implementation.
631
628
 
632
629
  Returns:
633
- list[Document]: List of documents that were found.
630
+ List of documents that were found.
634
631
  """
635
632
 
636
633
  async def aget(
@@ -653,10 +650,10 @@ class DocumentIndex(BaseRetriever):
653
650
 
654
651
  Args:
655
652
  ids: List of IDs to get.
656
- kwargs: Additional keyword arguments. These are up to the implementation.
653
+ **kwargs: Additional keyword arguments. These are up to the implementation.
657
654
 
658
655
  Returns:
659
- list[Document]: List of documents that were found.
656
+ List of documents that were found.
660
657
  """
661
658
  return await run_in_executor(
662
659
  None,
@@ -3,7 +3,7 @@
3
3
  import operator
4
4
  import uuid
5
5
  from collections.abc import Sequence
6
- from typing import Any, Optional, cast
6
+ from typing import Any, cast
7
7
 
8
8
  from pydantic import Field
9
9
  from typing_extensions import override
@@ -24,7 +24,7 @@ class InMemoryDocumentIndex(DocumentIndex):
24
24
  It provides a simple search API that returns documents by the number of
25
25
  counts the given query appears in the document.
26
26
 
27
- .. versionadded:: 0.2.29
27
+ !!! version-added "Added in version 0.2.29"
28
28
  """
29
29
 
30
30
  store: dict[str, Document] = Field(default_factory=dict)
@@ -32,7 +32,17 @@ class InMemoryDocumentIndex(DocumentIndex):
32
32
 
33
33
  @override
34
34
  def upsert(self, items: Sequence[Document], /, **kwargs: Any) -> UpsertResponse:
35
- """Upsert items into the index."""
35
+ """Upsert documents into the index.
36
+
37
+ Args:
38
+ items: Sequence of documents to add to the index.
39
+ **kwargs: Additional keyword arguments.
40
+
41
+ Returns:
42
+ A response object that contains the list of IDs that were
43
+ successfully added or updated in the index and the list of IDs that
44
+ failed to be added or updated.
45
+ """
36
46
  ok_ids = []
37
47
 
38
48
  for item in items:
@@ -50,8 +60,19 @@ class InMemoryDocumentIndex(DocumentIndex):
50
60
  return UpsertResponse(succeeded=ok_ids, failed=[])
51
61
 
52
62
  @override
53
- def delete(self, ids: Optional[list[str]] = None, **kwargs: Any) -> DeleteResponse:
54
- """Delete by ID."""
63
+ def delete(self, ids: list[str] | None = None, **kwargs: Any) -> DeleteResponse:
64
+ """Delete by IDs.
65
+
66
+ Args:
67
+ ids: List of ids to delete.
68
+
69
+ Raises:
70
+ ValueError: If ids is None.
71
+
72
+ Returns:
73
+ A response object that contains the list of IDs that were successfully
74
+ deleted and the list of IDs that failed to be deleted.
75
+ """
55
76
  if ids is None:
56
77
  msg = "IDs must be provided for deletion"
57
78
  raise ValueError(msg)
@@ -69,7 +90,6 @@ class InMemoryDocumentIndex(DocumentIndex):
69
90
 
70
91
  @override
71
92
  def get(self, ids: Sequence[str], /, **kwargs: Any) -> list[Document]:
72
- """Get by ids."""
73
93
  return [self.store[id_] for id_ in ids if id_ in self.store]
74
94
 
75
95
  @override
@@ -1,49 +1,35 @@
1
1
  """Language models.
2
2
 
3
- **Language Model** is a type of model that can generate text or complete
4
- text prompts.
3
+ LangChain has two main classes to work with language models: chat models and
4
+ "old-fashioned" LLMs.
5
5
 
6
- LangChain has two main classes to work with language models: **Chat Models**
7
- and "old-fashioned" **LLMs**.
8
-
9
- **Chat Models**
6
+ **Chat models**
10
7
 
11
8
  Language models that use a sequence of messages as inputs and return chat messages
12
- as outputs (as opposed to using plain text). These are traditionally newer models (
13
- older models are generally LLMs, see below). Chat models support the assignment of
9
+ as outputs (as opposed to using plain text). Chat models support the assignment of
14
10
  distinct roles to conversation messages, helping to distinguish messages from the AI,
15
11
  users, and instructions such as system messages.
16
12
 
17
13
  The key abstraction for chat models is `BaseChatModel`. Implementations
18
- should inherit from this class. Please see LangChain how-to guides with more
19
- information on how to implement a custom chat model.
20
-
21
- To implement a custom Chat Model, inherit from `BaseChatModel`. See
22
- the following guide for more information on how to implement a custom Chat Model:
14
+ should inherit from this class.
23
15
 
24
- https://python.langchain.com/docs/how_to/custom_chat_model/
16
+ See existing [chat model integrations](https://docs.langchain.com/oss/python/integrations/chat).
25
17
 
26
18
  **LLMs**
27
19
 
28
20
  Language models that takes a string as input and returns a string.
29
- These are traditionally older models (newer models generally are Chat Models, see below).
30
-
31
- Although the underlying models are string in, string out, the LangChain wrappers
32
- also allow these models to take messages as input. This gives them the same interface
33
- as Chat Models. When messages are passed in as input, they will be formatted into a
34
- string under the hood before being passed to the underlying model.
35
-
36
- To implement a custom LLM, inherit from `BaseLLM` or `LLM`.
37
- Please see the following guide for more information on how to implement a custom LLM:
38
-
39
- https://python.langchain.com/docs/how_to/custom_llm/
40
-
21
+ These are traditionally older models (newer models generally are chat models).
41
22
 
42
- """ # noqa: E501
23
+ Although the underlying models are string in, string out, the LangChain wrappers also
24
+ allow these models to take messages as input. This gives them the same interface as
25
+ chat models. When messages are passed in as input, they will be formatted into a string
26
+ under the hood before being passed to the underlying model.
27
+ """
43
28
 
44
29
  from typing import TYPE_CHECKING
45
30
 
46
31
  from langchain_core._import_utils import import_attr
32
+ from langchain_core.language_models._utils import is_openai_data_block
47
33
 
48
34
  if TYPE_CHECKING:
49
35
  from langchain_core.language_models.base import (
@@ -84,6 +70,7 @@ __all__ = (
84
70
  "ParrotFakeChatModel",
85
71
  "SimpleChatModel",
86
72
  "get_tokenizer",
73
+ "is_openai_data_block",
87
74
  )
88
75
 
89
76
  _dynamic_imports = {
@@ -103,6 +90,7 @@ _dynamic_imports = {
103
90
  "ParrotFakeChatModel": "fake_chat_models",
104
91
  "LLM": "llms",
105
92
  "BaseLLM": "llms",
93
+ "is_openai_data_block": "_utils",
106
94
  }
107
95
 
108
96