langchain-core 1.0.0rc3__py3-none-any.whl → 1.0.2__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.
- langchain_core/agents.py +2 -4
- langchain_core/caches.py +16 -7
- langchain_core/callbacks/base.py +0 -4
- langchain_core/callbacks/manager.py +0 -11
- langchain_core/chat_history.py +5 -5
- langchain_core/document_loaders/base.py +6 -4
- langchain_core/document_loaders/blob_loaders.py +1 -1
- langchain_core/document_loaders/langsmith.py +9 -13
- langchain_core/documents/__init__.py +24 -3
- langchain_core/documents/base.py +72 -61
- langchain_core/documents/compressor.py +6 -6
- langchain_core/documents/transformers.py +6 -6
- langchain_core/embeddings/fake.py +2 -2
- langchain_core/example_selectors/semantic_similarity.py +7 -7
- langchain_core/exceptions.py +2 -2
- langchain_core/indexing/__init__.py +1 -1
- langchain_core/indexing/api.py +62 -62
- langchain_core/indexing/base.py +20 -22
- langchain_core/indexing/in_memory.py +2 -4
- langchain_core/language_models/__init__.py +6 -5
- langchain_core/language_models/base.py +7 -8
- langchain_core/language_models/chat_models.py +84 -78
- langchain_core/language_models/fake_chat_models.py +1 -1
- langchain_core/language_models/llms.py +20 -18
- langchain_core/load/dump.py +6 -8
- langchain_core/load/serializable.py +4 -1
- langchain_core/messages/__init__.py +9 -0
- langchain_core/messages/ai.py +11 -7
- langchain_core/messages/base.py +4 -0
- langchain_core/messages/block_translators/google_genai.py +5 -3
- langchain_core/messages/content.py +4 -4
- langchain_core/messages/utils.py +17 -17
- langchain_core/output_parsers/__init__.py +17 -1
- langchain_core/output_parsers/base.py +3 -0
- langchain_core/output_parsers/format_instructions.py +9 -4
- langchain_core/output_parsers/json.py +5 -2
- langchain_core/output_parsers/list.py +16 -16
- langchain_core/output_parsers/openai_tools.py +2 -2
- langchain_core/output_parsers/pydantic.py +1 -1
- langchain_core/output_parsers/string.py +3 -3
- langchain_core/output_parsers/xml.py +28 -25
- langchain_core/outputs/generation.py +2 -3
- langchain_core/prompt_values.py +0 -6
- langchain_core/prompts/base.py +5 -3
- langchain_core/prompts/chat.py +60 -52
- langchain_core/prompts/string.py +5 -2
- langchain_core/prompts/structured.py +12 -8
- langchain_core/rate_limiters.py +1 -3
- langchain_core/retrievers.py +41 -37
- langchain_core/runnables/base.py +25 -29
- langchain_core/runnables/branch.py +9 -9
- langchain_core/runnables/config.py +2 -4
- langchain_core/runnables/configurable.py +3 -3
- langchain_core/runnables/fallbacks.py +1 -1
- langchain_core/runnables/graph.py +7 -3
- langchain_core/runnables/retry.py +1 -1
- langchain_core/runnables/schema.py +2 -5
- langchain_core/runnables/utils.py +3 -3
- langchain_core/stores.py +4 -6
- langchain_core/tools/base.py +68 -14
- langchain_core/tools/convert.py +8 -7
- langchain_core/tools/retriever.py +6 -5
- langchain_core/tools/structured.py +7 -5
- langchain_core/tracers/event_stream.py +4 -1
- langchain_core/tracers/log_stream.py +6 -3
- langchain_core/utils/function_calling.py +8 -0
- langchain_core/utils/json_schema.py +1 -1
- langchain_core/utils/strings.py +1 -4
- langchain_core/utils/utils.py +12 -5
- langchain_core/vectorstores/base.py +130 -130
- langchain_core/vectorstores/in_memory.py +4 -4
- langchain_core/vectorstores/utils.py +1 -1
- langchain_core/version.py +1 -1
- {langchain_core-1.0.0rc3.dist-info → langchain_core-1.0.2.dist-info}/METADATA +8 -7
- {langchain_core-1.0.0rc3.dist-info → langchain_core-1.0.2.dist-info}/RECORD +76 -76
- {langchain_core-1.0.0rc3.dist-info → langchain_core-1.0.2.dist-info}/WHEEL +0 -0
|
@@ -52,22 +52,22 @@ class VectorStore(ABC):
|
|
|
52
52
|
ids: list[str] | None = None,
|
|
53
53
|
**kwargs: Any,
|
|
54
54
|
) -> list[str]:
|
|
55
|
-
"""Run more texts through the embeddings and add to the
|
|
55
|
+
"""Run more texts through the embeddings and add to the `VectorStore`.
|
|
56
56
|
|
|
57
57
|
Args:
|
|
58
|
-
texts: Iterable of strings to add to the
|
|
58
|
+
texts: Iterable of strings to add to the `VectorStore`.
|
|
59
59
|
metadatas: Optional list of metadatas associated with the texts.
|
|
60
60
|
ids: Optional list of IDs associated with the texts.
|
|
61
|
-
**kwargs:
|
|
61
|
+
**kwargs: `VectorStore` specific parameters.
|
|
62
62
|
One of the kwargs should be `ids` which is a list of ids
|
|
63
63
|
associated with the texts.
|
|
64
64
|
|
|
65
65
|
Returns:
|
|
66
|
-
List of
|
|
66
|
+
List of IDs from adding the texts into the `VectorStore`.
|
|
67
67
|
|
|
68
68
|
Raises:
|
|
69
69
|
ValueError: If the number of metadatas does not match the number of texts.
|
|
70
|
-
ValueError: If the number of
|
|
70
|
+
ValueError: If the number of IDs does not match the number of texts.
|
|
71
71
|
"""
|
|
72
72
|
if type(self).add_documents != VectorStore.add_documents:
|
|
73
73
|
# This condition is triggered if the subclass has provided
|
|
@@ -109,11 +109,12 @@ class VectorStore(ABC):
|
|
|
109
109
|
"""Delete by vector ID or other criteria.
|
|
110
110
|
|
|
111
111
|
Args:
|
|
112
|
-
ids: List of
|
|
112
|
+
ids: List of IDs to delete. If `None`, delete all.
|
|
113
113
|
**kwargs: Other keyword arguments that subclasses might use.
|
|
114
114
|
|
|
115
115
|
Returns:
|
|
116
|
-
True if deletion is successful, False otherwise, None if not
|
|
116
|
+
`True` if deletion is successful, `False` otherwise, `None` if not
|
|
117
|
+
implemented.
|
|
117
118
|
"""
|
|
118
119
|
msg = "delete method must be implemented by subclass."
|
|
119
120
|
raise NotImplementedError(msg)
|
|
@@ -135,12 +136,10 @@ class VectorStore(ABC):
|
|
|
135
136
|
some IDs.
|
|
136
137
|
|
|
137
138
|
Args:
|
|
138
|
-
ids: List of
|
|
139
|
+
ids: List of IDs to retrieve.
|
|
139
140
|
|
|
140
141
|
Returns:
|
|
141
|
-
List of
|
|
142
|
-
|
|
143
|
-
!!! version-added "Added in version 0.2.11"
|
|
142
|
+
List of `Document` objects.
|
|
144
143
|
"""
|
|
145
144
|
msg = f"{self.__class__.__name__} does not yet support get_by_ids."
|
|
146
145
|
raise NotImplementedError(msg)
|
|
@@ -163,12 +162,10 @@ class VectorStore(ABC):
|
|
|
163
162
|
some IDs.
|
|
164
163
|
|
|
165
164
|
Args:
|
|
166
|
-
ids: List of
|
|
165
|
+
ids: List of IDs to retrieve.
|
|
167
166
|
|
|
168
167
|
Returns:
|
|
169
|
-
List of
|
|
170
|
-
|
|
171
|
-
!!! version-added "Added in version 0.2.11"
|
|
168
|
+
List of `Document` objects.
|
|
172
169
|
"""
|
|
173
170
|
return await run_in_executor(None, self.get_by_ids, ids)
|
|
174
171
|
|
|
@@ -176,11 +173,12 @@ class VectorStore(ABC):
|
|
|
176
173
|
"""Async delete by vector ID or other criteria.
|
|
177
174
|
|
|
178
175
|
Args:
|
|
179
|
-
ids: List of
|
|
176
|
+
ids: List of IDs to delete. If `None`, delete all.
|
|
180
177
|
**kwargs: Other keyword arguments that subclasses might use.
|
|
181
178
|
|
|
182
179
|
Returns:
|
|
183
|
-
True if deletion is successful, False otherwise, None if not
|
|
180
|
+
`True` if deletion is successful, `False` otherwise, `None` if not
|
|
181
|
+
implemented.
|
|
184
182
|
"""
|
|
185
183
|
return await run_in_executor(None, self.delete, ids, **kwargs)
|
|
186
184
|
|
|
@@ -192,20 +190,20 @@ class VectorStore(ABC):
|
|
|
192
190
|
ids: list[str] | None = None,
|
|
193
191
|
**kwargs: Any,
|
|
194
192
|
) -> list[str]:
|
|
195
|
-
"""Async run more texts through the embeddings and add to the
|
|
193
|
+
"""Async run more texts through the embeddings and add to the `VectorStore`.
|
|
196
194
|
|
|
197
195
|
Args:
|
|
198
|
-
texts: Iterable of strings to add to the
|
|
196
|
+
texts: Iterable of strings to add to the `VectorStore`.
|
|
199
197
|
metadatas: Optional list of metadatas associated with the texts.
|
|
200
198
|
ids: Optional list
|
|
201
|
-
**kwargs:
|
|
199
|
+
**kwargs: `VectorStore` specific parameters.
|
|
202
200
|
|
|
203
201
|
Returns:
|
|
204
|
-
List of
|
|
202
|
+
List of IDs from adding the texts into the `VectorStore`.
|
|
205
203
|
|
|
206
204
|
Raises:
|
|
207
205
|
ValueError: If the number of metadatas does not match the number of texts.
|
|
208
|
-
ValueError: If the number of
|
|
206
|
+
ValueError: If the number of IDs does not match the number of texts.
|
|
209
207
|
"""
|
|
210
208
|
if ids is not None:
|
|
211
209
|
# For backward compatibility
|
|
@@ -234,13 +232,13 @@ class VectorStore(ABC):
|
|
|
234
232
|
return await run_in_executor(None, self.add_texts, texts, metadatas, **kwargs)
|
|
235
233
|
|
|
236
234
|
def add_documents(self, documents: list[Document], **kwargs: Any) -> list[str]:
|
|
237
|
-
"""Add or update documents in the
|
|
235
|
+
"""Add or update documents in the `VectorStore`.
|
|
238
236
|
|
|
239
237
|
Args:
|
|
240
|
-
documents: Documents to add to the
|
|
238
|
+
documents: Documents to add to the `VectorStore`.
|
|
241
239
|
**kwargs: Additional keyword arguments.
|
|
242
|
-
if kwargs contains
|
|
243
|
-
the
|
|
240
|
+
if kwargs contains IDs and documents contain ids,
|
|
241
|
+
the IDs in the kwargs will receive precedence.
|
|
244
242
|
|
|
245
243
|
Returns:
|
|
246
244
|
List of IDs of the added texts.
|
|
@@ -266,10 +264,10 @@ class VectorStore(ABC):
|
|
|
266
264
|
async def aadd_documents(
|
|
267
265
|
self, documents: list[Document], **kwargs: Any
|
|
268
266
|
) -> list[str]:
|
|
269
|
-
"""Async run more documents through the embeddings and add to the
|
|
267
|
+
"""Async run more documents through the embeddings and add to the `VectorStore`.
|
|
270
268
|
|
|
271
269
|
Args:
|
|
272
|
-
documents: Documents to add to the
|
|
270
|
+
documents: Documents to add to the `VectorStore`.
|
|
273
271
|
**kwargs: Additional keyword arguments.
|
|
274
272
|
|
|
275
273
|
Returns:
|
|
@@ -295,17 +293,17 @@ class VectorStore(ABC):
|
|
|
295
293
|
"""Return docs most similar to query using a specified search type.
|
|
296
294
|
|
|
297
295
|
Args:
|
|
298
|
-
query: Input text
|
|
299
|
-
search_type: Type of search to perform. Can be
|
|
300
|
-
|
|
296
|
+
query: Input text.
|
|
297
|
+
search_type: Type of search to perform. Can be `'similarity'`, `'mmr'`, or
|
|
298
|
+
`'similarity_score_threshold'`.
|
|
301
299
|
**kwargs: Arguments to pass to the search method.
|
|
302
300
|
|
|
303
301
|
Returns:
|
|
304
|
-
List of
|
|
302
|
+
List of `Document` objects most similar to the query.
|
|
305
303
|
|
|
306
304
|
Raises:
|
|
307
|
-
ValueError: If search_type is not one of
|
|
308
|
-
|
|
305
|
+
ValueError: If `search_type` is not one of `'similarity'`,
|
|
306
|
+
`'mmr'`, or `'similarity_score_threshold'`.
|
|
309
307
|
"""
|
|
310
308
|
if search_type == "similarity":
|
|
311
309
|
return self.similarity_search(query, **kwargs)
|
|
@@ -330,16 +328,16 @@ class VectorStore(ABC):
|
|
|
330
328
|
|
|
331
329
|
Args:
|
|
332
330
|
query: Input text.
|
|
333
|
-
search_type: Type of search to perform. Can be
|
|
334
|
-
|
|
331
|
+
search_type: Type of search to perform. Can be `'similarity'`, `'mmr'`, or
|
|
332
|
+
`'similarity_score_threshold'`.
|
|
335
333
|
**kwargs: Arguments to pass to the search method.
|
|
336
334
|
|
|
337
335
|
Returns:
|
|
338
|
-
List of
|
|
336
|
+
List of `Document` objects most similar to the query.
|
|
339
337
|
|
|
340
338
|
Raises:
|
|
341
|
-
ValueError: If search_type is not one of
|
|
342
|
-
|
|
339
|
+
ValueError: If `search_type` is not one of `'similarity'`,
|
|
340
|
+
`'mmr'`, or `'similarity_score_threshold'`.
|
|
343
341
|
"""
|
|
344
342
|
if search_type == "similarity":
|
|
345
343
|
return await self.asimilarity_search(query, **kwargs)
|
|
@@ -364,11 +362,11 @@ class VectorStore(ABC):
|
|
|
364
362
|
|
|
365
363
|
Args:
|
|
366
364
|
query: Input text.
|
|
367
|
-
k: Number of
|
|
365
|
+
k: Number of `Document` objects to return.
|
|
368
366
|
**kwargs: Arguments to pass to the search method.
|
|
369
367
|
|
|
370
368
|
Returns:
|
|
371
|
-
List of
|
|
369
|
+
List of `Document` objects most similar to the query.
|
|
372
370
|
"""
|
|
373
371
|
|
|
374
372
|
@staticmethod
|
|
@@ -423,7 +421,7 @@ class VectorStore(ABC):
|
|
|
423
421
|
**kwargs: Arguments to pass to the search method.
|
|
424
422
|
|
|
425
423
|
Returns:
|
|
426
|
-
List of Tuples of (doc, similarity_score)
|
|
424
|
+
List of Tuples of `(doc, similarity_score)`.
|
|
427
425
|
"""
|
|
428
426
|
raise NotImplementedError
|
|
429
427
|
|
|
@@ -437,7 +435,7 @@ class VectorStore(ABC):
|
|
|
437
435
|
**kwargs: Arguments to pass to the search method.
|
|
438
436
|
|
|
439
437
|
Returns:
|
|
440
|
-
List of Tuples of (doc, similarity_score)
|
|
438
|
+
List of Tuples of `(doc, similarity_score)`.
|
|
441
439
|
"""
|
|
442
440
|
# This is a temporary workaround to make the similarity search
|
|
443
441
|
# asynchronous. The proper solution is to make the similarity search
|
|
@@ -455,19 +453,19 @@ class VectorStore(ABC):
|
|
|
455
453
|
"""Default similarity search with relevance scores.
|
|
456
454
|
|
|
457
455
|
Modify if necessary in subclass.
|
|
458
|
-
Return docs and relevance scores in the range [0, 1]
|
|
456
|
+
Return docs and relevance scores in the range `[0, 1]`.
|
|
459
457
|
|
|
460
|
-
0 is dissimilar, 1 is most similar.
|
|
458
|
+
`0` is dissimilar, `1` is most similar.
|
|
461
459
|
|
|
462
460
|
Args:
|
|
463
461
|
query: Input text.
|
|
464
|
-
k: Number of
|
|
465
|
-
**kwargs: kwargs to be passed to similarity search. Should include
|
|
466
|
-
score_threshold
|
|
467
|
-
|
|
462
|
+
k: Number of `Document` objects to return.
|
|
463
|
+
**kwargs: kwargs to be passed to similarity search. Should include
|
|
464
|
+
`score_threshold`, An optional floating point value between `0` to `1`
|
|
465
|
+
to filter the resulting set of retrieved docs
|
|
468
466
|
|
|
469
467
|
Returns:
|
|
470
|
-
List of Tuples of (doc, similarity_score)
|
|
468
|
+
List of Tuples of `(doc, similarity_score)`
|
|
471
469
|
"""
|
|
472
470
|
relevance_score_fn = self._select_relevance_score_fn()
|
|
473
471
|
docs_and_scores = self.similarity_search_with_score(query, k, **kwargs)
|
|
@@ -482,19 +480,19 @@ class VectorStore(ABC):
|
|
|
482
480
|
"""Default similarity search with relevance scores.
|
|
483
481
|
|
|
484
482
|
Modify if necessary in subclass.
|
|
485
|
-
Return docs and relevance scores in the range [0, 1]
|
|
483
|
+
Return docs and relevance scores in the range `[0, 1]`.
|
|
486
484
|
|
|
487
|
-
0 is dissimilar, 1 is most similar.
|
|
485
|
+
`0` is dissimilar, `1` is most similar.
|
|
488
486
|
|
|
489
487
|
Args:
|
|
490
488
|
query: Input text.
|
|
491
|
-
k: Number of
|
|
492
|
-
**kwargs: kwargs to be passed to similarity search. Should include
|
|
493
|
-
score_threshold
|
|
494
|
-
|
|
489
|
+
k: Number of `Document` objects to return.
|
|
490
|
+
**kwargs: kwargs to be passed to similarity search. Should include
|
|
491
|
+
`score_threshold`, An optional floating point value between `0` to `1`
|
|
492
|
+
to filter the resulting set of retrieved docs
|
|
495
493
|
|
|
496
494
|
Returns:
|
|
497
|
-
List of Tuples of (doc, similarity_score)
|
|
495
|
+
List of Tuples of `(doc, similarity_score)`
|
|
498
496
|
"""
|
|
499
497
|
relevance_score_fn = self._select_relevance_score_fn()
|
|
500
498
|
docs_and_scores = await self.asimilarity_search_with_score(query, k, **kwargs)
|
|
@@ -506,19 +504,19 @@ class VectorStore(ABC):
|
|
|
506
504
|
k: int = 4,
|
|
507
505
|
**kwargs: Any,
|
|
508
506
|
) -> list[tuple[Document, float]]:
|
|
509
|
-
"""Return docs and relevance scores in the range [0, 1]
|
|
507
|
+
"""Return docs and relevance scores in the range `[0, 1]`.
|
|
510
508
|
|
|
511
|
-
0 is dissimilar, 1 is most similar.
|
|
509
|
+
`0` is dissimilar, `1` is most similar.
|
|
512
510
|
|
|
513
511
|
Args:
|
|
514
512
|
query: Input text.
|
|
515
|
-
k: Number of
|
|
516
|
-
**kwargs: kwargs to be passed to similarity search. Should include
|
|
517
|
-
score_threshold
|
|
518
|
-
|
|
513
|
+
k: Number of `Document` objects to return.
|
|
514
|
+
**kwargs: kwargs to be passed to similarity search. Should include
|
|
515
|
+
`score_threshold`, An optional floating point value between `0` to `1`
|
|
516
|
+
to filter the resulting set of retrieved docs
|
|
519
517
|
|
|
520
518
|
Returns:
|
|
521
|
-
List of Tuples of (doc, similarity_score)
|
|
519
|
+
List of Tuples of `(doc, similarity_score)`.
|
|
522
520
|
"""
|
|
523
521
|
score_threshold = kwargs.pop("score_threshold", None)
|
|
524
522
|
|
|
@@ -555,19 +553,19 @@ class VectorStore(ABC):
|
|
|
555
553
|
k: int = 4,
|
|
556
554
|
**kwargs: Any,
|
|
557
555
|
) -> list[tuple[Document, float]]:
|
|
558
|
-
"""Async return docs and relevance scores in the range [0, 1]
|
|
556
|
+
"""Async return docs and relevance scores in the range `[0, 1]`.
|
|
559
557
|
|
|
560
|
-
0 is dissimilar, 1 is most similar.
|
|
558
|
+
`0` is dissimilar, `1` is most similar.
|
|
561
559
|
|
|
562
560
|
Args:
|
|
563
561
|
query: Input text.
|
|
564
|
-
k: Number of
|
|
565
|
-
**kwargs: kwargs to be passed to similarity search. Should include
|
|
566
|
-
score_threshold
|
|
567
|
-
|
|
562
|
+
k: Number of `Document` objects to return.
|
|
563
|
+
**kwargs: kwargs to be passed to similarity search. Should include
|
|
564
|
+
`score_threshold`, An optional floating point value between `0` to `1`
|
|
565
|
+
to filter the resulting set of retrieved docs
|
|
568
566
|
|
|
569
567
|
Returns:
|
|
570
|
-
List of Tuples of (doc, similarity_score)
|
|
568
|
+
List of Tuples of `(doc, similarity_score)`
|
|
571
569
|
"""
|
|
572
570
|
score_threshold = kwargs.pop("score_threshold", None)
|
|
573
571
|
|
|
@@ -605,11 +603,11 @@ class VectorStore(ABC):
|
|
|
605
603
|
|
|
606
604
|
Args:
|
|
607
605
|
query: Input text.
|
|
608
|
-
k: Number of
|
|
606
|
+
k: Number of `Document` objects to return.
|
|
609
607
|
**kwargs: Arguments to pass to the search method.
|
|
610
608
|
|
|
611
609
|
Returns:
|
|
612
|
-
List of
|
|
610
|
+
List of `Document` objects most similar to the query.
|
|
613
611
|
"""
|
|
614
612
|
# This is a temporary workaround to make the similarity search
|
|
615
613
|
# asynchronous. The proper solution is to make the similarity search
|
|
@@ -623,11 +621,11 @@ class VectorStore(ABC):
|
|
|
623
621
|
|
|
624
622
|
Args:
|
|
625
623
|
embedding: Embedding to look up documents similar to.
|
|
626
|
-
k: Number of
|
|
624
|
+
k: Number of `Document` objects to return.
|
|
627
625
|
**kwargs: Arguments to pass to the search method.
|
|
628
626
|
|
|
629
627
|
Returns:
|
|
630
|
-
List of
|
|
628
|
+
List of `Document` objects most similar to the query vector.
|
|
631
629
|
"""
|
|
632
630
|
raise NotImplementedError
|
|
633
631
|
|
|
@@ -638,11 +636,11 @@ class VectorStore(ABC):
|
|
|
638
636
|
|
|
639
637
|
Args:
|
|
640
638
|
embedding: Embedding to look up documents similar to.
|
|
641
|
-
k: Number of
|
|
639
|
+
k: Number of `Document` objects to return.
|
|
642
640
|
**kwargs: Arguments to pass to the search method.
|
|
643
641
|
|
|
644
642
|
Returns:
|
|
645
|
-
List of
|
|
643
|
+
List of `Document` objects most similar to the query vector.
|
|
646
644
|
"""
|
|
647
645
|
# This is a temporary workaround to make the similarity search
|
|
648
646
|
# asynchronous. The proper solution is to make the similarity search
|
|
@@ -666,15 +664,15 @@ class VectorStore(ABC):
|
|
|
666
664
|
|
|
667
665
|
Args:
|
|
668
666
|
query: Text to look up documents similar to.
|
|
669
|
-
k: Number of
|
|
670
|
-
fetch_k: Number of
|
|
671
|
-
lambda_mult: Number between 0 and 1 that determines the degree
|
|
667
|
+
k: Number of `Document` objects to return.
|
|
668
|
+
fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
|
|
669
|
+
lambda_mult: Number between `0` and `1` that determines the degree
|
|
672
670
|
of diversity among the results with 0 corresponding
|
|
673
|
-
to maximum diversity and 1 to minimum diversity.
|
|
671
|
+
to maximum diversity and `1` to minimum diversity.
|
|
674
672
|
**kwargs: Arguments to pass to the search method.
|
|
675
673
|
|
|
676
674
|
Returns:
|
|
677
|
-
List of
|
|
675
|
+
List of `Document` objects selected by maximal marginal relevance.
|
|
678
676
|
"""
|
|
679
677
|
raise NotImplementedError
|
|
680
678
|
|
|
@@ -693,15 +691,15 @@ class VectorStore(ABC):
|
|
|
693
691
|
|
|
694
692
|
Args:
|
|
695
693
|
query: Text to look up documents similar to.
|
|
696
|
-
k: Number of
|
|
697
|
-
fetch_k: Number of
|
|
698
|
-
lambda_mult: Number between 0 and 1 that determines the degree
|
|
694
|
+
k: Number of `Document` objects to return.
|
|
695
|
+
fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
|
|
696
|
+
lambda_mult: Number between `0` and `1` that determines the degree
|
|
699
697
|
of diversity among the results with 0 corresponding
|
|
700
|
-
to maximum diversity and 1 to minimum diversity.
|
|
698
|
+
to maximum diversity and `1` to minimum diversity.
|
|
701
699
|
**kwargs: Arguments to pass to the search method.
|
|
702
700
|
|
|
703
701
|
Returns:
|
|
704
|
-
List of
|
|
702
|
+
List of `Document` objects selected by maximal marginal relevance.
|
|
705
703
|
"""
|
|
706
704
|
# This is a temporary workaround to make the similarity search
|
|
707
705
|
# asynchronous. The proper solution is to make the similarity search
|
|
@@ -731,15 +729,15 @@ class VectorStore(ABC):
|
|
|
731
729
|
|
|
732
730
|
Args:
|
|
733
731
|
embedding: Embedding to look up documents similar to.
|
|
734
|
-
k: Number of
|
|
735
|
-
fetch_k: Number of
|
|
736
|
-
lambda_mult: Number between 0 and 1 that determines the degree
|
|
732
|
+
k: Number of `Document` objects to return.
|
|
733
|
+
fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
|
|
734
|
+
lambda_mult: Number between `0` and `1` that determines the degree
|
|
737
735
|
of diversity among the results with 0 corresponding
|
|
738
|
-
to maximum diversity and 1 to minimum diversity.
|
|
736
|
+
to maximum diversity and `1` to minimum diversity.
|
|
739
737
|
**kwargs: Arguments to pass to the search method.
|
|
740
738
|
|
|
741
739
|
Returns:
|
|
742
|
-
List of
|
|
740
|
+
List of `Document` objects selected by maximal marginal relevance.
|
|
743
741
|
"""
|
|
744
742
|
raise NotImplementedError
|
|
745
743
|
|
|
@@ -758,15 +756,15 @@ class VectorStore(ABC):
|
|
|
758
756
|
|
|
759
757
|
Args:
|
|
760
758
|
embedding: Embedding to look up documents similar to.
|
|
761
|
-
k: Number of
|
|
762
|
-
fetch_k: Number of
|
|
763
|
-
lambda_mult: Number between 0 and 1 that determines the degree
|
|
759
|
+
k: Number of `Document` objects to return.
|
|
760
|
+
fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
|
|
761
|
+
lambda_mult: Number between `0` and `1` that determines the degree
|
|
764
762
|
of diversity among the results with 0 corresponding
|
|
765
|
-
to maximum diversity and 1 to minimum diversity.
|
|
763
|
+
to maximum diversity and `1` to minimum diversity.
|
|
766
764
|
**kwargs: Arguments to pass to the search method.
|
|
767
765
|
|
|
768
766
|
Returns:
|
|
769
|
-
List of
|
|
767
|
+
List of `Document` objects selected by maximal marginal relevance.
|
|
770
768
|
"""
|
|
771
769
|
return await run_in_executor(
|
|
772
770
|
None,
|
|
@@ -785,15 +783,15 @@ class VectorStore(ABC):
|
|
|
785
783
|
embedding: Embeddings,
|
|
786
784
|
**kwargs: Any,
|
|
787
785
|
) -> Self:
|
|
788
|
-
"""Return VectorStore initialized from documents and embeddings.
|
|
786
|
+
"""Return `VectorStore` initialized from documents and embeddings.
|
|
789
787
|
|
|
790
788
|
Args:
|
|
791
|
-
documents: List of
|
|
789
|
+
documents: List of `Document` objects to add to the `VectorStore`.
|
|
792
790
|
embedding: Embedding function to use.
|
|
793
791
|
**kwargs: Additional keyword arguments.
|
|
794
792
|
|
|
795
793
|
Returns:
|
|
796
|
-
VectorStore initialized from documents and embeddings.
|
|
794
|
+
`VectorStore` initialized from documents and embeddings.
|
|
797
795
|
"""
|
|
798
796
|
texts = [d.page_content for d in documents]
|
|
799
797
|
metadatas = [d.metadata for d in documents]
|
|
@@ -815,15 +813,15 @@ class VectorStore(ABC):
|
|
|
815
813
|
embedding: Embeddings,
|
|
816
814
|
**kwargs: Any,
|
|
817
815
|
) -> Self:
|
|
818
|
-
"""Async return VectorStore initialized from documents and embeddings.
|
|
816
|
+
"""Async return `VectorStore` initialized from documents and embeddings.
|
|
819
817
|
|
|
820
818
|
Args:
|
|
821
|
-
documents: List of
|
|
819
|
+
documents: List of `Document` objects to add to the `VectorStore`.
|
|
822
820
|
embedding: Embedding function to use.
|
|
823
821
|
**kwargs: Additional keyword arguments.
|
|
824
822
|
|
|
825
823
|
Returns:
|
|
826
|
-
VectorStore initialized from documents and embeddings.
|
|
824
|
+
`VectorStore` initialized from documents and embeddings.
|
|
827
825
|
"""
|
|
828
826
|
texts = [d.page_content for d in documents]
|
|
829
827
|
metadatas = [d.metadata for d in documents]
|
|
@@ -849,17 +847,17 @@ class VectorStore(ABC):
|
|
|
849
847
|
ids: list[str] | None = None,
|
|
850
848
|
**kwargs: Any,
|
|
851
849
|
) -> VST:
|
|
852
|
-
"""Return VectorStore initialized from texts and embeddings.
|
|
850
|
+
"""Return `VectorStore` initialized from texts and embeddings.
|
|
853
851
|
|
|
854
852
|
Args:
|
|
855
|
-
texts: Texts to add to the
|
|
853
|
+
texts: Texts to add to the `VectorStore`.
|
|
856
854
|
embedding: Embedding function to use.
|
|
857
855
|
metadatas: Optional list of metadatas associated with the texts.
|
|
858
856
|
ids: Optional list of IDs associated with the texts.
|
|
859
857
|
**kwargs: Additional keyword arguments.
|
|
860
858
|
|
|
861
859
|
Returns:
|
|
862
|
-
VectorStore initialized from texts and embeddings.
|
|
860
|
+
`VectorStore` initialized from texts and embeddings.
|
|
863
861
|
"""
|
|
864
862
|
|
|
865
863
|
@classmethod
|
|
@@ -872,17 +870,17 @@ class VectorStore(ABC):
|
|
|
872
870
|
ids: list[str] | None = None,
|
|
873
871
|
**kwargs: Any,
|
|
874
872
|
) -> Self:
|
|
875
|
-
"""Async return VectorStore initialized from texts and embeddings.
|
|
873
|
+
"""Async return `VectorStore` initialized from texts and embeddings.
|
|
876
874
|
|
|
877
875
|
Args:
|
|
878
|
-
texts: Texts to add to the
|
|
876
|
+
texts: Texts to add to the `VectorStore`.
|
|
879
877
|
embedding: Embedding function to use.
|
|
880
878
|
metadatas: Optional list of metadatas associated with the texts.
|
|
881
879
|
ids: Optional list of IDs associated with the texts.
|
|
882
880
|
**kwargs: Additional keyword arguments.
|
|
883
881
|
|
|
884
882
|
Returns:
|
|
885
|
-
VectorStore initialized from texts and embeddings.
|
|
883
|
+
`VectorStore` initialized from texts and embeddings.
|
|
886
884
|
"""
|
|
887
885
|
if ids is not None:
|
|
888
886
|
kwargs["ids"] = ids
|
|
@@ -898,27 +896,29 @@ class VectorStore(ABC):
|
|
|
898
896
|
return tags
|
|
899
897
|
|
|
900
898
|
def as_retriever(self, **kwargs: Any) -> VectorStoreRetriever:
|
|
901
|
-
"""Return VectorStoreRetriever initialized from this VectorStore
|
|
899
|
+
"""Return `VectorStoreRetriever` initialized from this `VectorStore`.
|
|
902
900
|
|
|
903
901
|
Args:
|
|
904
902
|
**kwargs: Keyword arguments to pass to the search function.
|
|
905
903
|
Can include:
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
904
|
+
|
|
905
|
+
* `search_type`: Defines the type of search that the Retriever should
|
|
906
|
+
perform. Can be `'similarity'` (default), `'mmr'`, or
|
|
907
|
+
`'similarity_score_threshold'`.
|
|
908
|
+
* `search_kwargs`: Keyword arguments to pass to the search function. Can
|
|
910
909
|
include things like:
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
910
|
+
|
|
911
|
+
* `k`: Amount of documents to return (Default: `4`)
|
|
912
|
+
* `score_threshold`: Minimum relevance threshold
|
|
913
|
+
for `similarity_score_threshold`
|
|
914
|
+
* `fetch_k`: Amount of documents to pass to MMR algorithm
|
|
915
|
+
(Default: `20`)
|
|
916
|
+
* `lambda_mult`: Diversity of results returned by MMR;
|
|
917
|
+
`1` for minimum diversity and 0 for maximum. (Default: `0.5`)
|
|
918
|
+
* `filter`: Filter by document metadata
|
|
919
919
|
|
|
920
920
|
Returns:
|
|
921
|
-
Retriever class for VectorStore
|
|
921
|
+
Retriever class for `VectorStore`.
|
|
922
922
|
|
|
923
923
|
Examples:
|
|
924
924
|
```python
|
|
@@ -958,7 +958,7 @@ class VectorStoreRetriever(BaseRetriever):
|
|
|
958
958
|
vectorstore: VectorStore
|
|
959
959
|
"""VectorStore to use for retrieval."""
|
|
960
960
|
search_type: str = "similarity"
|
|
961
|
-
"""Type of search to perform.
|
|
961
|
+
"""Type of search to perform."""
|
|
962
962
|
search_kwargs: dict = Field(default_factory=dict)
|
|
963
963
|
"""Keyword arguments to pass to the search function."""
|
|
964
964
|
allowed_search_types: ClassVar[Collection[str]] = (
|
|
@@ -983,8 +983,8 @@ class VectorStoreRetriever(BaseRetriever):
|
|
|
983
983
|
Validated values.
|
|
984
984
|
|
|
985
985
|
Raises:
|
|
986
|
-
ValueError: If search_type is not one of the allowed search types.
|
|
987
|
-
ValueError: If score_threshold is not specified with a float value(0~1)
|
|
986
|
+
ValueError: If `search_type` is not one of the allowed search types.
|
|
987
|
+
ValueError: If `score_threshold` is not specified with a float value(`0~1`)
|
|
988
988
|
"""
|
|
989
989
|
search_type = values.get("search_type", "similarity")
|
|
990
990
|
if search_type not in cls.allowed_search_types:
|
|
@@ -1072,10 +1072,10 @@ class VectorStoreRetriever(BaseRetriever):
|
|
|
1072
1072
|
return docs
|
|
1073
1073
|
|
|
1074
1074
|
def add_documents(self, documents: list[Document], **kwargs: Any) -> list[str]:
|
|
1075
|
-
"""Add documents to the
|
|
1075
|
+
"""Add documents to the `VectorStore`.
|
|
1076
1076
|
|
|
1077
1077
|
Args:
|
|
1078
|
-
documents: Documents to add to the
|
|
1078
|
+
documents: Documents to add to the `VectorStore`.
|
|
1079
1079
|
**kwargs: Other keyword arguments that subclasses might use.
|
|
1080
1080
|
|
|
1081
1081
|
Returns:
|
|
@@ -1086,10 +1086,10 @@ class VectorStoreRetriever(BaseRetriever):
|
|
|
1086
1086
|
async def aadd_documents(
|
|
1087
1087
|
self, documents: list[Document], **kwargs: Any
|
|
1088
1088
|
) -> list[str]:
|
|
1089
|
-
"""Async add documents to the
|
|
1089
|
+
"""Async add documents to the `VectorStore`.
|
|
1090
1090
|
|
|
1091
1091
|
Args:
|
|
1092
|
-
documents: Documents to add to the
|
|
1092
|
+
documents: Documents to add to the `VectorStore`.
|
|
1093
1093
|
**kwargs: Other keyword arguments that subclasses might use.
|
|
1094
1094
|
|
|
1095
1095
|
Returns:
|
|
@@ -257,10 +257,10 @@ class InMemoryVectorStore(VectorStore):
|
|
|
257
257
|
"""Get documents by their ids.
|
|
258
258
|
|
|
259
259
|
Args:
|
|
260
|
-
ids: The
|
|
260
|
+
ids: The IDs of the documents to get.
|
|
261
261
|
|
|
262
262
|
Returns:
|
|
263
|
-
A list of Document objects.
|
|
263
|
+
A list of `Document` objects.
|
|
264
264
|
"""
|
|
265
265
|
documents = []
|
|
266
266
|
|
|
@@ -281,10 +281,10 @@ class InMemoryVectorStore(VectorStore):
|
|
|
281
281
|
"""Async get documents by their ids.
|
|
282
282
|
|
|
283
283
|
Args:
|
|
284
|
-
ids: The
|
|
284
|
+
ids: The IDs of the documents to get.
|
|
285
285
|
|
|
286
286
|
Returns:
|
|
287
|
-
A list of Document objects.
|
|
287
|
+
A list of `Document` objects.
|
|
288
288
|
"""
|
|
289
289
|
return self.get_by_ids(ids)
|
|
290
290
|
|
langchain_core/version.py
CHANGED