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/indexing/base.py
CHANGED
|
@@ -5,7 +5,7 @@ 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,
|
|
8
|
+
from typing import TYPE_CHECKING, Any, TypedDict
|
|
9
9
|
|
|
10
10
|
from typing_extensions import override
|
|
11
11
|
|
|
@@ -25,7 +25,7 @@ class RecordManager(ABC):
|
|
|
25
25
|
The record manager abstraction is used by the langchain indexing API.
|
|
26
26
|
|
|
27
27
|
The record manager keeps track of which documents have been
|
|
28
|
-
written into a
|
|
28
|
+
written into a `VectorStore` and when they were written.
|
|
29
29
|
|
|
30
30
|
The indexing API computes hashes for each document and stores the hash
|
|
31
31
|
together with the write time and the source id in the record manager.
|
|
@@ -37,7 +37,7 @@ class RecordManager(ABC):
|
|
|
37
37
|
already been indexed, and to only index new documents.
|
|
38
38
|
|
|
39
39
|
The main benefit of this abstraction is that it works across many vectorstores.
|
|
40
|
-
To be supported, a
|
|
40
|
+
To be supported, a `VectorStore` needs to only support the ability to add and
|
|
41
41
|
delete documents by ID. Using the record manager, the indexing API will
|
|
42
42
|
be able to delete outdated documents and avoid redundant indexing of documents
|
|
43
43
|
that have already been indexed.
|
|
@@ -45,13 +45,13 @@ class RecordManager(ABC):
|
|
|
45
45
|
The main constraints of this abstraction are:
|
|
46
46
|
|
|
47
47
|
1. It relies on the time-stamps to determine which documents have been
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
indexed and which have not. This means that the time-stamps must be
|
|
49
|
+
monotonically increasing. The timestamp should be the timestamp
|
|
50
|
+
as measured by the server to minimize issues.
|
|
51
51
|
2. The record manager is currently implemented separately from the
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
vectorstore, which means that the overall system becomes distributed
|
|
53
|
+
and may create issues with consistency. For example, writing to
|
|
54
|
+
record manager succeeds, but corresponding writing to `VectorStore` fails.
|
|
55
55
|
"""
|
|
56
56
|
|
|
57
57
|
def __init__(
|
|
@@ -61,7 +61,7 @@ class RecordManager(ABC):
|
|
|
61
61
|
"""Initialize the record manager.
|
|
62
62
|
|
|
63
63
|
Args:
|
|
64
|
-
namespace
|
|
64
|
+
namespace: The namespace for the record manager.
|
|
65
65
|
"""
|
|
66
66
|
self.namespace = namespace
|
|
67
67
|
|
|
@@ -100,8 +100,8 @@ class RecordManager(ABC):
|
|
|
100
100
|
self,
|
|
101
101
|
keys: Sequence[str],
|
|
102
102
|
*,
|
|
103
|
-
group_ids:
|
|
104
|
-
time_at_least:
|
|
103
|
+
group_ids: Sequence[str | None] | None = None,
|
|
104
|
+
time_at_least: float | None = None,
|
|
105
105
|
) -> None:
|
|
106
106
|
"""Upsert records into the database.
|
|
107
107
|
|
|
@@ -128,8 +128,8 @@ class RecordManager(ABC):
|
|
|
128
128
|
self,
|
|
129
129
|
keys: Sequence[str],
|
|
130
130
|
*,
|
|
131
|
-
group_ids:
|
|
132
|
-
time_at_least:
|
|
131
|
+
group_ids: Sequence[str | None] | None = None,
|
|
132
|
+
time_at_least: float | None = None,
|
|
133
133
|
) -> None:
|
|
134
134
|
"""Asynchronously upsert records into the database.
|
|
135
135
|
|
|
@@ -177,10 +177,10 @@ class RecordManager(ABC):
|
|
|
177
177
|
def list_keys(
|
|
178
178
|
self,
|
|
179
179
|
*,
|
|
180
|
-
before:
|
|
181
|
-
after:
|
|
182
|
-
group_ids:
|
|
183
|
-
limit:
|
|
180
|
+
before: float | None = None,
|
|
181
|
+
after: float | None = None,
|
|
182
|
+
group_ids: Sequence[str] | None = None,
|
|
183
|
+
limit: int | None = None,
|
|
184
184
|
) -> list[str]:
|
|
185
185
|
"""List records in the database based on the provided filters.
|
|
186
186
|
|
|
@@ -198,10 +198,10 @@ class RecordManager(ABC):
|
|
|
198
198
|
async def alist_keys(
|
|
199
199
|
self,
|
|
200
200
|
*,
|
|
201
|
-
before:
|
|
202
|
-
after:
|
|
203
|
-
group_ids:
|
|
204
|
-
limit:
|
|
201
|
+
before: float | None = None,
|
|
202
|
+
after: float | None = None,
|
|
203
|
+
group_ids: Sequence[str] | None = None,
|
|
204
|
+
limit: int | None = None,
|
|
205
205
|
) -> list[str]:
|
|
206
206
|
"""Asynchronously list records in the database based on the provided filters.
|
|
207
207
|
|
|
@@ -233,7 +233,7 @@ class RecordManager(ABC):
|
|
|
233
233
|
|
|
234
234
|
|
|
235
235
|
class _Record(TypedDict):
|
|
236
|
-
group_id:
|
|
236
|
+
group_id: str | None
|
|
237
237
|
updated_at: float
|
|
238
238
|
|
|
239
239
|
|
|
@@ -244,7 +244,7 @@ class InMemoryRecordManager(RecordManager):
|
|
|
244
244
|
"""Initialize the in-memory record manager.
|
|
245
245
|
|
|
246
246
|
Args:
|
|
247
|
-
namespace
|
|
247
|
+
namespace: The namespace for the record manager.
|
|
248
248
|
"""
|
|
249
249
|
super().__init__(namespace)
|
|
250
250
|
# Each key points to a dictionary
|
|
@@ -270,18 +270,18 @@ class InMemoryRecordManager(RecordManager):
|
|
|
270
270
|
self,
|
|
271
271
|
keys: Sequence[str],
|
|
272
272
|
*,
|
|
273
|
-
group_ids:
|
|
274
|
-
time_at_least:
|
|
273
|
+
group_ids: Sequence[str | None] | None = None,
|
|
274
|
+
time_at_least: float | None = None,
|
|
275
275
|
) -> None:
|
|
276
276
|
"""Upsert records into the database.
|
|
277
277
|
|
|
278
278
|
Args:
|
|
279
279
|
keys: A list of record keys to upsert.
|
|
280
280
|
group_ids: A list of group IDs corresponding to the keys.
|
|
281
|
-
|
|
281
|
+
|
|
282
282
|
time_at_least: Optional timestamp. Implementation can use this
|
|
283
283
|
to optionally verify that the timestamp IS at least this time
|
|
284
|
-
in the system that stores.
|
|
284
|
+
in the system that stores.
|
|
285
285
|
E.g., use to validate that the time in the postgres database
|
|
286
286
|
is equal to or larger than the given timestamp, if not
|
|
287
287
|
raise an error.
|
|
@@ -307,18 +307,18 @@ class InMemoryRecordManager(RecordManager):
|
|
|
307
307
|
self,
|
|
308
308
|
keys: Sequence[str],
|
|
309
309
|
*,
|
|
310
|
-
group_ids:
|
|
311
|
-
time_at_least:
|
|
310
|
+
group_ids: Sequence[str | None] | None = None,
|
|
311
|
+
time_at_least: float | None = None,
|
|
312
312
|
) -> None:
|
|
313
313
|
"""Async upsert records into the database.
|
|
314
314
|
|
|
315
315
|
Args:
|
|
316
316
|
keys: A list of record keys to upsert.
|
|
317
317
|
group_ids: A list of group IDs corresponding to the keys.
|
|
318
|
-
|
|
318
|
+
|
|
319
319
|
time_at_least: Optional timestamp. Implementation can use this
|
|
320
320
|
to optionally verify that the timestamp IS at least this time
|
|
321
|
-
in the system that stores.
|
|
321
|
+
in the system that stores.
|
|
322
322
|
E.g., use to validate that the time in the postgres database
|
|
323
323
|
is equal to or larger than the given timestamp, if not
|
|
324
324
|
raise an error.
|
|
@@ -352,22 +352,22 @@ class InMemoryRecordManager(RecordManager):
|
|
|
352
352
|
def list_keys(
|
|
353
353
|
self,
|
|
354
354
|
*,
|
|
355
|
-
before:
|
|
356
|
-
after:
|
|
357
|
-
group_ids:
|
|
358
|
-
limit:
|
|
355
|
+
before: float | None = None,
|
|
356
|
+
after: float | None = None,
|
|
357
|
+
group_ids: Sequence[str] | None = None,
|
|
358
|
+
limit: int | None = None,
|
|
359
359
|
) -> list[str]:
|
|
360
360
|
"""List records in the database based on the provided filters.
|
|
361
361
|
|
|
362
362
|
Args:
|
|
363
363
|
before: Filter to list records updated before this time.
|
|
364
|
-
|
|
364
|
+
|
|
365
365
|
after: Filter to list records updated after this time.
|
|
366
|
-
|
|
366
|
+
|
|
367
367
|
group_ids: Filter to list records with specific group IDs.
|
|
368
|
-
|
|
368
|
+
|
|
369
369
|
limit: optional limit on the number of records to return.
|
|
370
|
-
|
|
370
|
+
|
|
371
371
|
|
|
372
372
|
Returns:
|
|
373
373
|
A list of keys for the matching records.
|
|
@@ -388,22 +388,22 @@ class InMemoryRecordManager(RecordManager):
|
|
|
388
388
|
async def alist_keys(
|
|
389
389
|
self,
|
|
390
390
|
*,
|
|
391
|
-
before:
|
|
392
|
-
after:
|
|
393
|
-
group_ids:
|
|
394
|
-
limit:
|
|
391
|
+
before: float | None = None,
|
|
392
|
+
after: float | None = None,
|
|
393
|
+
group_ids: Sequence[str] | None = None,
|
|
394
|
+
limit: int | None = None,
|
|
395
395
|
) -> list[str]:
|
|
396
396
|
"""Async list records in the database based on the provided filters.
|
|
397
397
|
|
|
398
398
|
Args:
|
|
399
399
|
before: Filter to list records updated before this time.
|
|
400
|
-
|
|
400
|
+
|
|
401
401
|
after: Filter to list records updated after this time.
|
|
402
|
-
|
|
402
|
+
|
|
403
403
|
group_ids: Filter to list records with specific group IDs.
|
|
404
|
-
|
|
404
|
+
|
|
405
405
|
limit: optional limit on the number of records to return.
|
|
406
|
-
|
|
406
|
+
|
|
407
407
|
|
|
408
408
|
Returns:
|
|
409
409
|
A list of keys for the matching records.
|
|
@@ -460,7 +460,7 @@ class UpsertResponse(TypedDict):
|
|
|
460
460
|
class DeleteResponse(TypedDict, total=False):
|
|
461
461
|
"""A generic response for delete operation.
|
|
462
462
|
|
|
463
|
-
The fields in this response are optional and whether the
|
|
463
|
+
The fields in this response are optional and whether the `VectorStore`
|
|
464
464
|
returns them or not is up to the implementation.
|
|
465
465
|
"""
|
|
466
466
|
|
|
@@ -485,7 +485,7 @@ class DeleteResponse(TypedDict, total=False):
|
|
|
485
485
|
failed: Sequence[str]
|
|
486
486
|
"""The IDs that failed to be deleted.
|
|
487
487
|
|
|
488
|
-
|
|
488
|
+
!!! warning
|
|
489
489
|
Deleting an ID that does not exist is **NOT** considered a failure.
|
|
490
490
|
"""
|
|
491
491
|
|
|
@@ -508,8 +508,6 @@ class DocumentIndex(BaseRetriever):
|
|
|
508
508
|
1. Storing document in the index.
|
|
509
509
|
2. Fetching document by ID.
|
|
510
510
|
3. Searching for document using a query.
|
|
511
|
-
|
|
512
|
-
.. versionadded:: 0.2.29
|
|
513
511
|
"""
|
|
514
512
|
|
|
515
513
|
@abc.abstractmethod
|
|
@@ -520,40 +518,40 @@ class DocumentIndex(BaseRetriever):
|
|
|
520
518
|
if it is provided. If the ID is not provided, the upsert method is free
|
|
521
519
|
to generate an ID for the content.
|
|
522
520
|
|
|
523
|
-
When an ID is specified and the content already exists in the
|
|
521
|
+
When an ID is specified and the content already exists in the `VectorStore`,
|
|
524
522
|
the upsert method should update the content with the new data. If the content
|
|
525
|
-
does not exist, the upsert method should add the item to the
|
|
523
|
+
does not exist, the upsert method should add the item to the `VectorStore`.
|
|
526
524
|
|
|
527
525
|
Args:
|
|
528
|
-
items: Sequence of documents to add to the
|
|
526
|
+
items: Sequence of documents to add to the `VectorStore`.
|
|
529
527
|
**kwargs: Additional keyword arguments.
|
|
530
528
|
|
|
531
529
|
Returns:
|
|
532
|
-
|
|
533
|
-
successfully added or updated in the
|
|
530
|
+
A response object that contains the list of IDs that were
|
|
531
|
+
successfully added or updated in the `VectorStore` and the list of IDs that
|
|
534
532
|
failed to be added or updated.
|
|
535
533
|
"""
|
|
536
534
|
|
|
537
535
|
async def aupsert(
|
|
538
536
|
self, items: Sequence[Document], /, **kwargs: Any
|
|
539
537
|
) -> UpsertResponse:
|
|
540
|
-
"""Add or update documents in the
|
|
538
|
+
"""Add or update documents in the `VectorStore`. Async version of `upsert`.
|
|
541
539
|
|
|
542
540
|
The upsert functionality should utilize the ID field of the item
|
|
543
541
|
if it is provided. If the ID is not provided, the upsert method is free
|
|
544
542
|
to generate an ID for the item.
|
|
545
543
|
|
|
546
|
-
When an ID is specified and the item already exists in the
|
|
544
|
+
When an ID is specified and the item already exists in the `VectorStore`,
|
|
547
545
|
the upsert method should update the item with the new data. If the item
|
|
548
|
-
does not exist, the upsert method should add the item to the
|
|
546
|
+
does not exist, the upsert method should add the item to the `VectorStore`.
|
|
549
547
|
|
|
550
548
|
Args:
|
|
551
|
-
items: Sequence of documents to add to the
|
|
549
|
+
items: Sequence of documents to add to the `VectorStore`.
|
|
552
550
|
**kwargs: Additional keyword arguments.
|
|
553
551
|
|
|
554
552
|
Returns:
|
|
555
|
-
|
|
556
|
-
successfully added or updated in the
|
|
553
|
+
A response object that contains the list of IDs that were
|
|
554
|
+
successfully added or updated in the `VectorStore` and the list of IDs that
|
|
557
555
|
failed to be added or updated.
|
|
558
556
|
"""
|
|
559
557
|
return await run_in_executor(
|
|
@@ -564,36 +562,36 @@ class DocumentIndex(BaseRetriever):
|
|
|
564
562
|
)
|
|
565
563
|
|
|
566
564
|
@abc.abstractmethod
|
|
567
|
-
def delete(self, ids:
|
|
565
|
+
def delete(self, ids: list[str] | None = None, **kwargs: Any) -> DeleteResponse:
|
|
568
566
|
"""Delete by IDs or other criteria.
|
|
569
567
|
|
|
570
568
|
Calling delete without any input parameters should raise a ValueError!
|
|
571
569
|
|
|
572
570
|
Args:
|
|
573
|
-
ids: List of
|
|
574
|
-
kwargs: Additional keyword arguments. This is up to the implementation.
|
|
571
|
+
ids: List of IDs to delete.
|
|
572
|
+
**kwargs: Additional keyword arguments. This is up to the implementation.
|
|
575
573
|
For example, can include an option to delete the entire index,
|
|
576
574
|
or else issue a non-blocking delete etc.
|
|
577
575
|
|
|
578
576
|
Returns:
|
|
579
|
-
|
|
577
|
+
A response object that contains the list of IDs that were
|
|
580
578
|
successfully deleted and the list of IDs that failed to be deleted.
|
|
581
579
|
"""
|
|
582
580
|
|
|
583
581
|
async def adelete(
|
|
584
|
-
self, ids:
|
|
582
|
+
self, ids: list[str] | None = None, **kwargs: Any
|
|
585
583
|
) -> DeleteResponse:
|
|
586
584
|
"""Delete by IDs or other criteria. Async variant.
|
|
587
585
|
|
|
588
586
|
Calling adelete without any input parameters should raise a ValueError!
|
|
589
587
|
|
|
590
588
|
Args:
|
|
591
|
-
ids: List of
|
|
592
|
-
kwargs: Additional keyword arguments. This is up to the implementation.
|
|
589
|
+
ids: List of IDs to delete.
|
|
590
|
+
**kwargs: Additional keyword arguments. This is up to the implementation.
|
|
593
591
|
For example, can include an option to delete the entire index.
|
|
594
592
|
|
|
595
593
|
Returns:
|
|
596
|
-
|
|
594
|
+
A response object that contains the list of IDs that were
|
|
597
595
|
successfully deleted and the list of IDs that failed to be deleted.
|
|
598
596
|
"""
|
|
599
597
|
return await run_in_executor(
|
|
@@ -624,10 +622,10 @@ class DocumentIndex(BaseRetriever):
|
|
|
624
622
|
|
|
625
623
|
Args:
|
|
626
624
|
ids: List of IDs to get.
|
|
627
|
-
kwargs: Additional keyword arguments. These are up to the implementation.
|
|
625
|
+
**kwargs: Additional keyword arguments. These are up to the implementation.
|
|
628
626
|
|
|
629
627
|
Returns:
|
|
630
|
-
|
|
628
|
+
List of documents that were found.
|
|
631
629
|
"""
|
|
632
630
|
|
|
633
631
|
async def aget(
|
|
@@ -650,10 +648,10 @@ class DocumentIndex(BaseRetriever):
|
|
|
650
648
|
|
|
651
649
|
Args:
|
|
652
650
|
ids: List of IDs to get.
|
|
653
|
-
kwargs: Additional keyword arguments. These are up to the implementation.
|
|
651
|
+
**kwargs: Additional keyword arguments. These are up to the implementation.
|
|
654
652
|
|
|
655
653
|
Returns:
|
|
656
|
-
|
|
654
|
+
List of documents that were found.
|
|
657
655
|
"""
|
|
658
656
|
return await run_in_executor(
|
|
659
657
|
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,
|
|
6
|
+
from typing import Any, cast
|
|
7
7
|
|
|
8
8
|
from pydantic import Field
|
|
9
9
|
from typing_extensions import override
|
|
@@ -23,8 +23,6 @@ class InMemoryDocumentIndex(DocumentIndex):
|
|
|
23
23
|
|
|
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
|
-
|
|
27
|
-
.. versionadded:: 0.2.29
|
|
28
26
|
"""
|
|
29
27
|
|
|
30
28
|
store: dict[str, Document] = Field(default_factory=dict)
|
|
@@ -60,14 +58,14 @@ class InMemoryDocumentIndex(DocumentIndex):
|
|
|
60
58
|
return UpsertResponse(succeeded=ok_ids, failed=[])
|
|
61
59
|
|
|
62
60
|
@override
|
|
63
|
-
def delete(self, ids:
|
|
61
|
+
def delete(self, ids: list[str] | None = None, **kwargs: Any) -> DeleteResponse:
|
|
64
62
|
"""Delete by IDs.
|
|
65
63
|
|
|
66
64
|
Args:
|
|
67
|
-
ids: List of
|
|
65
|
+
ids: List of IDs to delete.
|
|
68
66
|
|
|
69
67
|
Raises:
|
|
70
|
-
ValueError: If
|
|
68
|
+
ValueError: If IDs is None.
|
|
71
69
|
|
|
72
70
|
Returns:
|
|
73
71
|
A response object that contains the list of IDs that were successfully
|
|
@@ -1,45 +1,30 @@
|
|
|
1
1
|
"""Language models.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
LangChain has two main classes to work with language models: chat models and
|
|
4
|
+
"old-fashioned" LLMs.
|
|
5
5
|
|
|
6
|
-
|
|
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).
|
|
13
|
-
older models are generally LLMs, see below). Chat models support the assignment of
|
|
14
|
-
distinct roles to conversation messages, helping to distinguish messages from the AI,
|
|
15
|
-
users, and instructions such as system messages.
|
|
9
|
+
as outputs (as opposed to using plain text).
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
information on how to implement a custom chat model.
|
|
11
|
+
Chat models support the assignment of distinct roles to conversation messages, helping
|
|
12
|
+
to distinguish messages from the AI, users, and instructions such as system messages.
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
The key abstraction for chat models is `BaseChatModel`. Implementations should inherit
|
|
15
|
+
from this class.
|
|
23
16
|
|
|
24
|
-
https://
|
|
17
|
+
See existing [chat model integrations](https://docs.langchain.com/oss/python/integrations/chat).
|
|
25
18
|
|
|
26
19
|
**LLMs**
|
|
27
20
|
|
|
28
21
|
Language models that takes a string as input and returns a string.
|
|
29
|
-
These are traditionally older models (newer models generally are
|
|
30
|
-
see below).
|
|
31
|
-
|
|
32
|
-
Although the underlying models are string in, string out, the LangChain wrappers
|
|
33
|
-
also allow these models to take messages as input. This gives them the same interface
|
|
34
|
-
as Chat Models. When messages are passed in as input, they will be formatted into a
|
|
35
|
-
string under the hood before being passed to the underlying model.
|
|
36
|
-
|
|
37
|
-
To implement a custom LLM, inherit from `BaseLLM` or `LLM`.
|
|
38
|
-
Please see the following guide for more information on how to implement a custom LLM:
|
|
39
|
-
|
|
40
|
-
https://python.langchain.com/docs/how_to/custom_llm/
|
|
41
|
-
|
|
22
|
+
These are traditionally older models (newer models generally are chat models).
|
|
42
23
|
|
|
24
|
+
Although the underlying models are string in, string out, the LangChain wrappers also
|
|
25
|
+
allow these models to take messages as input. This gives them the same interface as
|
|
26
|
+
chat models. When messages are passed in as input, they will be formatted into a string
|
|
27
|
+
under the hood before being passed to the underlying model.
|
|
43
28
|
"""
|
|
44
29
|
|
|
45
30
|
from typing import TYPE_CHECKING
|