langchain-core 1.0.0a6__py3-none-any.whl → 1.0.0a8__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 (131) hide show
  1. langchain_core/_api/__init__.py +3 -3
  2. langchain_core/_api/beta_decorator.py +6 -6
  3. langchain_core/_api/deprecation.py +21 -29
  4. langchain_core/_api/path.py +3 -6
  5. langchain_core/_import_utils.py +2 -3
  6. langchain_core/agents.py +10 -11
  7. langchain_core/caches.py +7 -7
  8. langchain_core/callbacks/base.py +91 -91
  9. langchain_core/callbacks/file.py +11 -11
  10. langchain_core/callbacks/manager.py +86 -89
  11. langchain_core/callbacks/stdout.py +8 -8
  12. langchain_core/callbacks/usage.py +4 -4
  13. langchain_core/chat_history.py +5 -5
  14. langchain_core/document_loaders/base.py +2 -2
  15. langchain_core/document_loaders/langsmith.py +15 -15
  16. langchain_core/documents/base.py +16 -16
  17. langchain_core/documents/compressor.py +4 -4
  18. langchain_core/example_selectors/length_based.py +1 -1
  19. langchain_core/example_selectors/semantic_similarity.py +17 -19
  20. langchain_core/exceptions.py +3 -3
  21. langchain_core/globals.py +3 -151
  22. langchain_core/indexing/api.py +44 -43
  23. langchain_core/indexing/base.py +30 -30
  24. langchain_core/indexing/in_memory.py +3 -3
  25. langchain_core/language_models/_utils.py +5 -7
  26. langchain_core/language_models/base.py +18 -132
  27. langchain_core/language_models/chat_models.py +118 -227
  28. langchain_core/language_models/fake.py +11 -11
  29. langchain_core/language_models/fake_chat_models.py +35 -29
  30. langchain_core/language_models/llms.py +91 -201
  31. langchain_core/load/dump.py +1 -1
  32. langchain_core/load/load.py +11 -12
  33. langchain_core/load/mapping.py +2 -4
  34. langchain_core/load/serializable.py +2 -4
  35. langchain_core/messages/ai.py +17 -20
  36. langchain_core/messages/base.py +23 -25
  37. langchain_core/messages/block_translators/__init__.py +2 -5
  38. langchain_core/messages/block_translators/anthropic.py +3 -3
  39. langchain_core/messages/block_translators/bedrock_converse.py +2 -2
  40. langchain_core/messages/block_translators/langchain_v0.py +2 -2
  41. langchain_core/messages/block_translators/openai.py +6 -6
  42. langchain_core/messages/content.py +120 -124
  43. langchain_core/messages/human.py +7 -7
  44. langchain_core/messages/system.py +7 -7
  45. langchain_core/messages/tool.py +24 -24
  46. langchain_core/messages/utils.py +67 -79
  47. langchain_core/output_parsers/base.py +12 -14
  48. langchain_core/output_parsers/json.py +4 -4
  49. langchain_core/output_parsers/list.py +3 -5
  50. langchain_core/output_parsers/openai_functions.py +3 -3
  51. langchain_core/output_parsers/openai_tools.py +3 -3
  52. langchain_core/output_parsers/pydantic.py +2 -2
  53. langchain_core/output_parsers/transform.py +13 -15
  54. langchain_core/output_parsers/xml.py +7 -9
  55. langchain_core/outputs/chat_generation.py +4 -4
  56. langchain_core/outputs/chat_result.py +1 -3
  57. langchain_core/outputs/generation.py +2 -2
  58. langchain_core/outputs/llm_result.py +5 -5
  59. langchain_core/prompts/__init__.py +1 -5
  60. langchain_core/prompts/base.py +10 -15
  61. langchain_core/prompts/chat.py +31 -82
  62. langchain_core/prompts/dict.py +2 -2
  63. langchain_core/prompts/few_shot.py +5 -5
  64. langchain_core/prompts/few_shot_with_templates.py +4 -4
  65. langchain_core/prompts/loading.py +3 -5
  66. langchain_core/prompts/prompt.py +4 -16
  67. langchain_core/prompts/string.py +2 -1
  68. langchain_core/prompts/structured.py +16 -23
  69. langchain_core/rate_limiters.py +3 -4
  70. langchain_core/retrievers.py +14 -14
  71. langchain_core/runnables/base.py +928 -1042
  72. langchain_core/runnables/branch.py +36 -40
  73. langchain_core/runnables/config.py +27 -35
  74. langchain_core/runnables/configurable.py +108 -124
  75. langchain_core/runnables/fallbacks.py +76 -72
  76. langchain_core/runnables/graph.py +39 -45
  77. langchain_core/runnables/graph_ascii.py +9 -11
  78. langchain_core/runnables/graph_mermaid.py +18 -19
  79. langchain_core/runnables/graph_png.py +8 -9
  80. langchain_core/runnables/history.py +114 -127
  81. langchain_core/runnables/passthrough.py +113 -139
  82. langchain_core/runnables/retry.py +43 -48
  83. langchain_core/runnables/router.py +23 -28
  84. langchain_core/runnables/schema.py +42 -44
  85. langchain_core/runnables/utils.py +28 -31
  86. langchain_core/stores.py +9 -13
  87. langchain_core/structured_query.py +8 -8
  88. langchain_core/tools/base.py +62 -115
  89. langchain_core/tools/convert.py +31 -35
  90. langchain_core/tools/render.py +1 -1
  91. langchain_core/tools/retriever.py +4 -4
  92. langchain_core/tools/simple.py +13 -17
  93. langchain_core/tools/structured.py +12 -15
  94. langchain_core/tracers/base.py +62 -64
  95. langchain_core/tracers/context.py +17 -35
  96. langchain_core/tracers/core.py +49 -53
  97. langchain_core/tracers/evaluation.py +11 -11
  98. langchain_core/tracers/event_stream.py +58 -60
  99. langchain_core/tracers/langchain.py +13 -13
  100. langchain_core/tracers/log_stream.py +22 -24
  101. langchain_core/tracers/root_listeners.py +14 -14
  102. langchain_core/tracers/run_collector.py +2 -4
  103. langchain_core/tracers/schemas.py +8 -8
  104. langchain_core/tracers/stdout.py +2 -1
  105. langchain_core/utils/__init__.py +0 -3
  106. langchain_core/utils/_merge.py +2 -2
  107. langchain_core/utils/aiter.py +24 -28
  108. langchain_core/utils/env.py +4 -4
  109. langchain_core/utils/function_calling.py +31 -41
  110. langchain_core/utils/html.py +3 -4
  111. langchain_core/utils/input.py +3 -3
  112. langchain_core/utils/iter.py +15 -19
  113. langchain_core/utils/json.py +3 -2
  114. langchain_core/utils/json_schema.py +6 -6
  115. langchain_core/utils/mustache.py +3 -5
  116. langchain_core/utils/pydantic.py +16 -18
  117. langchain_core/utils/usage.py +1 -1
  118. langchain_core/utils/utils.py +29 -29
  119. langchain_core/vectorstores/base.py +18 -21
  120. langchain_core/vectorstores/in_memory.py +14 -87
  121. langchain_core/vectorstores/utils.py +2 -2
  122. langchain_core/version.py +1 -1
  123. {langchain_core-1.0.0a6.dist-info → langchain_core-1.0.0a8.dist-info}/METADATA +10 -21
  124. langchain_core-1.0.0a8.dist-info/RECORD +176 -0
  125. {langchain_core-1.0.0a6.dist-info → langchain_core-1.0.0a8.dist-info}/WHEEL +1 -1
  126. langchain_core/messages/block_translators/ollama.py +0 -47
  127. langchain_core/prompts/pipeline.py +0 -138
  128. langchain_core/tracers/langchain_v1.py +0 -31
  129. langchain_core/utils/loading.py +0 -35
  130. langchain_core-1.0.0a6.dist-info/RECORD +0 -181
  131. langchain_core-1.0.0a6.dist-info/entry_points.txt +0 -4
@@ -6,9 +6,9 @@ import functools
6
6
  import importlib
7
7
  import os
8
8
  import warnings
9
- from collections.abc import Iterator, Sequence
9
+ from collections.abc import Callable, Iterator, Sequence
10
10
  from importlib.metadata import version
11
- from typing import Any, Callable, Optional, Union, overload
11
+ from typing import Any, overload
12
12
  from uuid import uuid4
13
13
 
14
14
  from packaging.version import parse
@@ -91,7 +91,7 @@ def mock_now(dt_value: datetime.datetime) -> Iterator[type]:
91
91
 
92
92
  @classmethod
93
93
  @override
94
- def now(cls, tz: Union[datetime.tzinfo, None] = None) -> "MockDateTime":
94
+ def now(cls, tz: datetime.tzinfo | None = None) -> "MockDateTime":
95
95
  # Create a copy of dt_value.
96
96
  return MockDateTime(
97
97
  dt_value.year,
@@ -113,7 +113,7 @@ def mock_now(dt_value: datetime.datetime) -> Iterator[type]:
113
113
 
114
114
 
115
115
  def guard_import(
116
- module_name: str, *, pip_name: Optional[str] = None, package: Optional[str] = None
116
+ module_name: str, *, pip_name: str | None = None, package: str | None = None
117
117
  ) -> Any:
118
118
  """Dynamically import a module.
119
119
 
@@ -146,10 +146,10 @@ def guard_import(
146
146
 
147
147
  def check_package_version(
148
148
  package: str,
149
- lt_version: Optional[str] = None,
150
- lte_version: Optional[str] = None,
151
- gt_version: Optional[str] = None,
152
- gte_version: Optional[str] = None,
149
+ lt_version: str | None = None,
150
+ lte_version: str | None = None,
151
+ gt_version: str | None = None,
152
+ gte_version: str | None = None,
153
153
  ) -> None:
154
154
  """Check the version of a package.
155
155
 
@@ -306,7 +306,7 @@ def build_extra_kwargs(
306
306
  return extra_kwargs
307
307
 
308
308
 
309
- def convert_to_secret_str(value: Union[SecretStr, str]) -> SecretStr:
309
+ def convert_to_secret_str(value: SecretStr | str) -> SecretStr:
310
310
  """Convert a string to a SecretStr if needed.
311
311
 
312
312
  Args:
@@ -345,29 +345,29 @@ def from_env(key: str, /, *, error_message: str) -> Callable[[], str]: ...
345
345
 
346
346
  @overload
347
347
  def from_env(
348
- key: Union[str, Sequence[str]], /, *, default: str, error_message: Optional[str]
348
+ key: str | Sequence[str], /, *, default: str, error_message: str | None
349
349
  ) -> Callable[[], str]: ...
350
350
 
351
351
 
352
352
  @overload
353
353
  def from_env(
354
- key: str, /, *, default: None, error_message: Optional[str]
355
- ) -> Callable[[], Optional[str]]: ...
354
+ key: str, /, *, default: None, error_message: str | None
355
+ ) -> Callable[[], str | None]: ...
356
356
 
357
357
 
358
358
  @overload
359
359
  def from_env(
360
- key: Union[str, Sequence[str]], /, *, default: None
361
- ) -> Callable[[], Optional[str]]: ...
360
+ key: str | Sequence[str], /, *, default: None
361
+ ) -> Callable[[], str | None]: ...
362
362
 
363
363
 
364
364
  def from_env(
365
- key: Union[str, Sequence[str]],
365
+ key: str | Sequence[str],
366
366
  /,
367
367
  *,
368
- default: Union[str, _NoDefaultType, None] = _NoDefault,
369
- error_message: Optional[str] = None,
370
- ) -> Union[Callable[[], str], Callable[[], Optional[str]]]:
368
+ default: str | _NoDefaultType | None = _NoDefault,
369
+ error_message: str | None = None,
370
+ ) -> Callable[[], str] | Callable[[], str | None]:
371
371
  """Create a factory method that gets a value from an environment variable.
372
372
 
373
373
  Args:
@@ -384,7 +384,7 @@ def from_env(
384
384
  factory method that will look up the value from the environment.
385
385
  """
386
386
 
387
- def get_from_env_fn() -> Optional[str]:
387
+ def get_from_env_fn() -> str | None:
388
388
  """Get a value from an environment variable.
389
389
 
390
390
  Raises:
@@ -416,7 +416,7 @@ def from_env(
416
416
 
417
417
 
418
418
  @overload
419
- def secret_from_env(key: Union[str, Sequence[str]], /) -> Callable[[], SecretStr]: ...
419
+ def secret_from_env(key: str | Sequence[str], /) -> Callable[[], SecretStr]: ...
420
420
 
421
421
 
422
422
  @overload
@@ -425,8 +425,8 @@ def secret_from_env(key: str, /, *, default: str) -> Callable[[], SecretStr]: ..
425
425
 
426
426
  @overload
427
427
  def secret_from_env(
428
- key: Union[str, Sequence[str]], /, *, default: None
429
- ) -> Callable[[], Optional[SecretStr]]: ...
428
+ key: str | Sequence[str], /, *, default: None
429
+ ) -> Callable[[], SecretStr | None]: ...
430
430
 
431
431
 
432
432
  @overload
@@ -434,12 +434,12 @@ def secret_from_env(key: str, /, *, error_message: str) -> Callable[[], SecretSt
434
434
 
435
435
 
436
436
  def secret_from_env(
437
- key: Union[str, Sequence[str]],
437
+ key: str | Sequence[str],
438
438
  /,
439
439
  *,
440
- default: Union[str, _NoDefaultType, None] = _NoDefault,
441
- error_message: Optional[str] = None,
442
- ) -> Union[Callable[[], Optional[SecretStr]], Callable[[], SecretStr]]:
440
+ default: str | _NoDefaultType | None = _NoDefault,
441
+ error_message: str | None = None,
442
+ ) -> Callable[[], SecretStr | None] | Callable[[], SecretStr]:
443
443
  """Secret from env.
444
444
 
445
445
  Args:
@@ -453,7 +453,7 @@ def secret_from_env(
453
453
  factory method that will look up the secret from the environment.
454
454
  """
455
455
 
456
- def get_secret_from_env() -> Optional[SecretStr]:
456
+ def get_secret_from_env() -> SecretStr | None:
457
457
  """Get a value from an environment variable.
458
458
 
459
459
  Raises:
@@ -498,7 +498,7 @@ Used for:
498
498
  """
499
499
 
500
500
 
501
- def ensure_id(id_val: Optional[str]) -> str:
501
+ def ensure_id(id_val: str | None) -> str:
502
502
  """Ensure the ID is a valid string, generating a new UUID if not provided.
503
503
 
504
504
  Auto-generated UUIDs are prefixed by ``'lc_'`` to indicate they are
@@ -510,4 +510,4 @@ def ensure_id(id_val: Optional[str]) -> str:
510
510
  Returns:
511
511
  A string ID, either the validated provided value or a newly generated UUID4.
512
512
  """
513
- return id_val or str(f"{LC_AUTO_PREFIX}{uuid4()}")
513
+ return id_val or f"{LC_AUTO_PREFIX}{uuid4()}"
@@ -25,13 +25,12 @@ import logging
25
25
  import math
26
26
  import warnings
27
27
  from abc import ABC, abstractmethod
28
+ from collections.abc import Callable
28
29
  from itertools import cycle
29
30
  from typing import (
30
31
  TYPE_CHECKING,
31
32
  Any,
32
- Callable,
33
33
  ClassVar,
34
- Optional,
35
34
  TypeVar,
36
35
  )
37
36
 
@@ -62,9 +61,9 @@ class VectorStore(ABC):
62
61
  def add_texts(
63
62
  self,
64
63
  texts: Iterable[str],
65
- metadatas: Optional[list[dict]] = None,
64
+ metadatas: list[dict] | None = None,
66
65
  *,
67
- ids: Optional[list[str]] = None,
66
+ ids: list[str] | None = None,
68
67
  **kwargs: Any,
69
68
  ) -> list[str]:
70
69
  """Run more texts through the embeddings and add to the vectorstore.
@@ -98,10 +97,10 @@ class VectorStore(ABC):
98
97
  )
99
98
  raise ValueError(msg)
100
99
  metadatas_ = iter(metadatas) if metadatas else cycle([{}])
101
- ids_: Iterator[Optional[str]] = iter(ids) if ids else cycle([None])
100
+ ids_: Iterator[str | None] = iter(ids) if ids else cycle([None])
102
101
  docs = [
103
102
  Document(id=id_, page_content=text, metadata=metadata_)
104
- for text, metadata_, id_ in zip(texts, metadatas_, ids_)
103
+ for text, metadata_, id_ in zip(texts, metadatas_, ids_, strict=False)
105
104
  ]
106
105
  if ids is not None:
107
106
  # For backward compatibility
@@ -112,7 +111,7 @@ class VectorStore(ABC):
112
111
  raise NotImplementedError(msg)
113
112
 
114
113
  @property
115
- def embeddings(self) -> Optional[Embeddings]:
114
+ def embeddings(self) -> Embeddings | None:
116
115
  """Access the query embedding object if available."""
117
116
  logger.debug(
118
117
  "The embeddings property has not been implemented for %s",
@@ -120,7 +119,7 @@ class VectorStore(ABC):
120
119
  )
121
120
  return None
122
121
 
123
- def delete(self, ids: Optional[list[str]] = None, **kwargs: Any) -> Optional[bool]:
122
+ def delete(self, ids: list[str] | None = None, **kwargs: Any) -> bool | None:
124
123
  """Delete by vector ID or other criteria.
125
124
 
126
125
  Args:
@@ -156,7 +155,7 @@ class VectorStore(ABC):
156
155
  Returns:
157
156
  List of Documents.
158
157
 
159
- .. versionadded:: 0.2.11
158
+ !!! version-added "Added in version 0.2.11"
160
159
  """
161
160
  msg = f"{self.__class__.__name__} does not yet support get_by_ids."
162
161
  raise NotImplementedError(msg)
@@ -184,13 +183,11 @@ class VectorStore(ABC):
184
183
  Returns:
185
184
  List of Documents.
186
185
 
187
- .. versionadded:: 0.2.11
186
+ !!! version-added "Added in version 0.2.11"
188
187
  """
189
188
  return await run_in_executor(None, self.get_by_ids, ids)
190
189
 
191
- async def adelete(
192
- self, ids: Optional[list[str]] = None, **kwargs: Any
193
- ) -> Optional[bool]:
190
+ async def adelete(self, ids: list[str] | None = None, **kwargs: Any) -> bool | None:
194
191
  """Async delete by vector ID or other criteria.
195
192
 
196
193
  Args:
@@ -206,9 +203,9 @@ class VectorStore(ABC):
206
203
  async def aadd_texts(
207
204
  self,
208
205
  texts: Iterable[str],
209
- metadatas: Optional[list[dict]] = None,
206
+ metadatas: list[dict] | None = None,
210
207
  *,
211
- ids: Optional[list[str]] = None,
208
+ ids: list[str] | None = None,
212
209
  **kwargs: Any,
213
210
  ) -> list[str]:
214
211
  """Async run more texts through the embeddings and add to the vectorstore.
@@ -244,11 +241,11 @@ class VectorStore(ABC):
244
241
  )
245
242
  raise ValueError(msg)
246
243
  metadatas_ = iter(metadatas) if metadatas else cycle([{}])
247
- ids_: Iterator[Optional[str]] = iter(ids) if ids else cycle([None])
244
+ ids_: Iterator[str | None] = iter(ids) if ids else cycle([None])
248
245
 
249
246
  docs = [
250
247
  Document(id=id_, page_content=text, metadata=metadata_)
251
- for text, metadata_, id_ in zip(texts, metadatas_, ids_)
248
+ for text, metadata_, id_ in zip(texts, metadatas_, ids_, strict=False)
252
249
  ]
253
250
  return await self.aadd_documents(docs, **kwargs)
254
251
  return await run_in_executor(None, self.add_texts, texts, metadatas, **kwargs)
@@ -872,9 +869,9 @@ class VectorStore(ABC):
872
869
  cls: type[VST],
873
870
  texts: list[str],
874
871
  embedding: Embeddings,
875
- metadatas: Optional[list[dict]] = None,
872
+ metadatas: list[dict] | None = None,
876
873
  *,
877
- ids: Optional[list[str]] = None,
874
+ ids: list[str] | None = None,
878
875
  **kwargs: Any,
879
876
  ) -> VST:
880
877
  """Return VectorStore initialized from texts and embeddings.
@@ -896,9 +893,9 @@ class VectorStore(ABC):
896
893
  cls,
897
894
  texts: list[str],
898
895
  embedding: Embeddings,
899
- metadatas: Optional[list[dict]] = None,
896
+ metadatas: list[dict] | None = None,
900
897
  *,
901
- ids: Optional[list[str]] = None,
898
+ ids: list[str] | None = None,
902
899
  **kwargs: Any,
903
900
  ) -> Self:
904
901
  """Async return VectorStore initialized from texts and embeddings.
@@ -4,17 +4,15 @@ from __future__ import annotations
4
4
 
5
5
  import json
6
6
  import uuid
7
+ from collections.abc import Callable
7
8
  from pathlib import Path
8
9
  from typing import (
9
10
  TYPE_CHECKING,
10
11
  Any,
11
- Callable,
12
- Optional,
13
12
  )
14
13
 
15
14
  from typing_extensions import override
16
15
 
17
- from langchain_core._api import deprecated
18
16
  from langchain_core.documents import Document
19
17
  from langchain_core.load import dumpd, load
20
18
  from langchain_core.vectorstores import VectorStore
@@ -25,7 +23,6 @@ if TYPE_CHECKING:
25
23
  from collections.abc import Iterator, Sequence
26
24
 
27
25
  from langchain_core.embeddings import Embeddings
28
- from langchain_core.indexing import UpsertResponse
29
26
 
30
27
  try:
31
28
  import numpy as np
@@ -180,20 +177,20 @@ class InMemoryVectorStore(VectorStore):
180
177
  return self.embedding
181
178
 
182
179
  @override
183
- def delete(self, ids: Optional[Sequence[str]] = None, **kwargs: Any) -> None:
180
+ def delete(self, ids: Sequence[str] | None = None, **kwargs: Any) -> None:
184
181
  if ids:
185
182
  for _id in ids:
186
183
  self.store.pop(_id, None)
187
184
 
188
185
  @override
189
- async def adelete(self, ids: Optional[Sequence[str]] = None, **kwargs: Any) -> None:
186
+ async def adelete(self, ids: Sequence[str] | None = None, **kwargs: Any) -> None:
190
187
  self.delete(ids)
191
188
 
192
189
  @override
193
190
  def add_documents(
194
191
  self,
195
192
  documents: list[Document],
196
- ids: Optional[list[str]] = None,
193
+ ids: list[str] | None = None,
197
194
  **kwargs: Any,
198
195
  ) -> list[str]:
199
196
  texts = [doc.page_content for doc in documents]
@@ -206,13 +203,13 @@ class InMemoryVectorStore(VectorStore):
206
203
  )
207
204
  raise ValueError(msg)
208
205
 
209
- id_iterator: Iterator[Optional[str]] = (
206
+ id_iterator: Iterator[str | None] = (
210
207
  iter(ids) if ids else iter(doc.id for doc in documents)
211
208
  )
212
209
 
213
210
  ids_ = []
214
211
 
215
- for doc, vector in zip(documents, vectors):
212
+ for doc, vector in zip(documents, vectors, strict=False):
216
213
  doc_id = next(id_iterator)
217
214
  doc_id_ = doc_id or str(uuid.uuid4())
218
215
  ids_.append(doc_id_)
@@ -227,7 +224,7 @@ class InMemoryVectorStore(VectorStore):
227
224
 
228
225
  @override
229
226
  async def aadd_documents(
230
- self, documents: list[Document], ids: Optional[list[str]] = None, **kwargs: Any
227
+ self, documents: list[Document], ids: list[str] | None = None, **kwargs: Any
231
228
  ) -> list[str]:
232
229
  texts = [doc.page_content for doc in documents]
233
230
  vectors = await self.embedding.aembed_documents(texts)
@@ -239,12 +236,12 @@ class InMemoryVectorStore(VectorStore):
239
236
  )
240
237
  raise ValueError(msg)
241
238
 
242
- id_iterator: Iterator[Optional[str]] = (
239
+ id_iterator: Iterator[str | None] = (
243
240
  iter(ids) if ids else iter(doc.id for doc in documents)
244
241
  )
245
242
  ids_: list[str] = []
246
243
 
247
- for doc, vector in zip(documents, vectors):
244
+ for doc, vector in zip(documents, vectors, strict=False):
248
245
  doc_id = next(id_iterator)
249
246
  doc_id_ = doc_id or str(uuid.uuid4())
250
247
  ids_.append(doc_id_)
@@ -281,76 +278,6 @@ class InMemoryVectorStore(VectorStore):
281
278
  )
282
279
  return documents
283
280
 
284
- @deprecated(
285
- alternative="VectorStore.add_documents",
286
- message=(
287
- "This was a beta API that was added in 0.2.11. It'll be removed in 0.3.0."
288
- ),
289
- since="0.2.29",
290
- removal="1.0",
291
- )
292
- def upsert(self, items: Sequence[Document], /, **_kwargs: Any) -> UpsertResponse:
293
- """[DEPRECATED] Upsert documents into the store.
294
-
295
- Args:
296
- items: The documents to upsert.
297
-
298
- Returns:
299
- The upsert response.
300
- """
301
- vectors = self.embedding.embed_documents([item.page_content for item in items])
302
- ids = []
303
- for item, vector in zip(items, vectors):
304
- doc_id = item.id or str(uuid.uuid4())
305
- ids.append(doc_id)
306
- self.store[doc_id] = {
307
- "id": doc_id,
308
- "vector": vector,
309
- "text": item.page_content,
310
- "metadata": item.metadata,
311
- }
312
- return {
313
- "succeeded": ids,
314
- "failed": [],
315
- }
316
-
317
- @deprecated(
318
- alternative="VectorStore.aadd_documents",
319
- message=(
320
- "This was a beta API that was added in 0.2.11. It'll be removed in 0.3.0."
321
- ),
322
- since="0.2.29",
323
- removal="1.0",
324
- )
325
- async def aupsert(
326
- self, items: Sequence[Document], /, **_kwargs: Any
327
- ) -> UpsertResponse:
328
- """[DEPRECATED] Upsert documents into the store.
329
-
330
- Args:
331
- items: The documents to upsert.
332
-
333
- Returns:
334
- The upsert response.
335
- """
336
- vectors = await self.embedding.aembed_documents(
337
- [item.page_content for item in items]
338
- )
339
- ids = []
340
- for item, vector in zip(items, vectors):
341
- doc_id = item.id or str(uuid.uuid4())
342
- ids.append(doc_id)
343
- self.store[doc_id] = {
344
- "id": doc_id,
345
- "vector": vector,
346
- "text": item.page_content,
347
- "metadata": item.metadata,
348
- }
349
- return {
350
- "succeeded": ids,
351
- "failed": [],
352
- }
353
-
354
281
  @override
355
282
  async def aget_by_ids(self, ids: Sequence[str], /) -> list[Document]:
356
283
  """Async get documents by their ids.
@@ -367,7 +294,7 @@ class InMemoryVectorStore(VectorStore):
367
294
  self,
368
295
  embedding: list[float],
369
296
  k: int = 4,
370
- filter: Optional[Callable[[Document], bool]] = None, # noqa: A002
297
+ filter: Callable[[Document], bool] | None = None, # noqa: A002
371
298
  ) -> list[tuple[Document, float, list[float]]]:
372
299
  # get all docs with fixed order in list
373
300
  docs = list(self.store.values())
@@ -410,7 +337,7 @@ class InMemoryVectorStore(VectorStore):
410
337
  self,
411
338
  embedding: list[float],
412
339
  k: int = 4,
413
- filter: Optional[Callable[[Document], bool]] = None, # noqa: A002
340
+ filter: Callable[[Document], bool] | None = None, # noqa: A002
414
341
  **_kwargs: Any,
415
342
  ) -> list[tuple[Document, float]]:
416
343
  """Search for the most similar documents to the given embedding.
@@ -498,7 +425,7 @@ class InMemoryVectorStore(VectorStore):
498
425
  fetch_k: int = 20,
499
426
  lambda_mult: float = 0.5,
500
427
  *,
501
- filter: Optional[Callable[[Document], bool]] = None,
428
+ filter: Callable[[Document], bool] | None = None,
502
429
  **kwargs: Any,
503
430
  ) -> list[Document]:
504
431
  prefetch_hits = self._similarity_search_with_score_by_vector(
@@ -564,7 +491,7 @@ class InMemoryVectorStore(VectorStore):
564
491
  cls,
565
492
  texts: list[str],
566
493
  embedding: Embeddings,
567
- metadatas: Optional[list[dict]] = None,
494
+ metadatas: list[dict] | None = None,
568
495
  **kwargs: Any,
569
496
  ) -> InMemoryVectorStore:
570
497
  store = cls(
@@ -579,7 +506,7 @@ class InMemoryVectorStore(VectorStore):
579
506
  cls,
580
507
  texts: list[str],
581
508
  embedding: Embeddings,
582
- metadatas: Optional[list[dict]] = None,
509
+ metadatas: list[dict] | None = None,
583
510
  **kwargs: Any,
584
511
  ) -> InMemoryVectorStore:
585
512
  store = cls(
@@ -8,7 +8,7 @@ from __future__ import annotations
8
8
 
9
9
  import logging
10
10
  import warnings
11
- from typing import TYPE_CHECKING, Union
11
+ from typing import TYPE_CHECKING
12
12
 
13
13
  try:
14
14
  import numpy as np
@@ -25,7 +25,7 @@ except ImportError:
25
25
  _HAS_SIMSIMD = False
26
26
 
27
27
  if TYPE_CHECKING:
28
- Matrix = Union[list[list[float]], list[np.ndarray], np.ndarray]
28
+ Matrix = list[list[float]] | list[np.ndarray] | np.ndarray
29
29
 
30
30
  logger = logging.getLogger(__name__)
31
31
 
langchain_core/version.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """langchain-core version information and utilities."""
2
2
 
3
- VERSION = "1.0.0a6"
3
+ VERSION = "1.0.0a8"
@@ -1,19 +1,19 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: langchain-core
3
- Version: 1.0.0a6
3
+ Version: 1.0.0a8
4
4
  Summary: Building applications with LLMs through composability
5
- License: MIT
6
5
  Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/core
7
6
  Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain-core%3D%3D0%22&expanded=true
8
7
  Project-URL: repository, https://github.com/langchain-ai/langchain
8
+ License: MIT
9
9
  Requires-Python: <4.0.0,>=3.10.0
10
- Requires-Dist: langsmith<1.0.0,>=0.3.45
11
- Requires-Dist: tenacity!=8.4.0,<10.0.0,>=8.1.0
12
10
  Requires-Dist: jsonpatch<2.0.0,>=1.33.0
13
- Requires-Dist: PyYAML<7.0.0,>=5.3.0
14
- Requires-Dist: typing-extensions<5.0.0,>=4.7.0
11
+ Requires-Dist: langsmith<1.0.0,>=0.3.45
15
12
  Requires-Dist: packaging<26.0.0,>=23.2.0
16
13
  Requires-Dist: pydantic<3.0.0,>=2.7.4
14
+ Requires-Dist: pyyaml<7.0.0,>=5.3.0
15
+ Requires-Dist: tenacity!=8.4.0,<10.0.0,>=8.1.0
16
+ Requires-Dist: typing-extensions<5.0.0,>=4.7.0
17
17
  Description-Content-Type: text/markdown
18
18
 
19
19
  # 🦜🍎️ LangChain Core
@@ -35,7 +35,7 @@ These abstractions are designed to be as modular and simple as possible.
35
35
 
36
36
  The benefit of having these abstractions is that any provider can implement the required interface and then easily be used in the rest of the LangChain ecosystem.
37
37
 
38
- For full documentation see the [API reference](https://python.langchain.com/api_reference/core/index.html).
38
+ For full documentation see the [API reference](https://reference.langchain.com/python/).
39
39
 
40
40
  ## ⛰️ Why build on top of LangChain Core?
41
41
 
@@ -47,21 +47,10 @@ The LangChain ecosystem is built on top of `langchain-core`. Some of the benefit
47
47
 
48
48
  ## 📕 Releases & Versioning
49
49
 
50
- As `langchain-core` contains the base abstractions and runtime for the whole LangChain ecosystem, we will communicate any breaking changes with advance notice and version bumps. The exception for this is anything in `langchain_core.beta`. The reason for `langchain_core.beta` is that given the rate of change of the field, being able to move quickly is still a priority, and this module is our attempt to do so.
51
-
52
- Minor version increases will occur for:
53
-
54
- - Breaking changes for any public interfaces NOT in `langchain_core.beta`
55
-
56
- Patch version increases will occur for:
57
-
58
- - Bug fixes
59
- - New features
60
- - Any changes to private interfaces
61
- - Any changes to `langchain_core.beta`
50
+ See our [Releases](https://docs.langchain.com/oss/python/release-policy) and [Versioning Policy](https://docs.langchain.com/oss/python/versioning).
62
51
 
63
52
  ## 💁 Contributing
64
53
 
65
54
  As an open-source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infrastructure, or better documentation.
66
55
 
67
- For detailed information on how to contribute, see the [Contributing Guide](https://python.langchain.com/docs/contributing/).
56
+ For detailed information on how to contribute, see the [Contributing Guide](https://docs.langchain.com/oss/python/contributing).