test_add_documents_with_existing_ids() — langchain Function Reference
Architecture documentation for the test_add_documents_with_existing_ids() function in vectorstores.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c69c0a82_61fd_d2a5_3518_af78a767d45c["test_add_documents_with_existing_ids()"] 6b7f515d_5b14_acff_3191_2493436e519d["VectorStoreIntegrationTests"] c69c0a82_61fd_d2a5_3518_af78a767d45c -->|defined in| 6b7f515d_5b14_acff_3191_2493436e519d c509032a_5234_60e4_9090_cf461c5a7aee["has_get_by_ids()"] c69c0a82_61fd_d2a5_3518_af78a767d45c -->|calls| c509032a_5234_60e4_9090_cf461c5a7aee 5c40f02c_d060_0a02_88bc_e7140f97f945["_sort_by_id()"] c69c0a82_61fd_d2a5_3518_af78a767d45c -->|calls| 5c40f02c_d060_0a02_88bc_e7140f97f945 style c69c0a82_61fd_d2a5_3518_af78a767d45c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/vectorstores.py lines 440–484
def test_add_documents_with_existing_ids(self, vectorstore: VectorStore) -> None:
"""Test that `add_documents` with existing IDs is idempotent.
??? note "Troubleshooting"
If this test fails, check that `get_by_ids` is implemented and returns
documents in the same order as the IDs passed in.
This test also verifies that:
1. IDs specified in the `Document.id` field are assigned when adding
documents.
2. If some documents include IDs and others don't string IDs are generated
for the latter.
!!! note
`get_by_ids` was added to the `VectorStore` interface in
`langchain-core` version 0.2.11. If difficult to implement, this
test can be skipped by setting the `has_get_by_ids` property to
`False`.
```python
@property
def has_get_by_ids(self) -> bool:
return False
```
"""
if not self.has_sync:
pytest.skip("Sync tests not supported.")
if not self.has_get_by_ids:
pytest.skip("get_by_ids not implemented.")
documents = [
Document(id="foo", page_content="foo", metadata={"id": 1}),
Document(page_content="bar", metadata={"id": 2}),
]
ids = vectorstore.add_documents(documents)
assert "foo" in ids
assert _sort_by_id(vectorstore.get_by_ids(ids)) == _sort_by_id(
[
Document(page_content="foo", metadata={"id": 1}, id="foo"),
Document(page_content="bar", metadata={"id": 2}, id=ids[1]),
]
)
Domain
Subdomains
Source
Frequently Asked Questions
What does test_add_documents_with_existing_ids() do?
test_add_documents_with_existing_ids() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/vectorstores.py.
Where is test_add_documents_with_existing_ids() defined?
test_add_documents_with_existing_ids() is defined in libs/standard-tests/langchain_tests/integration_tests/vectorstores.py at line 440.
What does test_add_documents_with_existing_ids() call?
test_add_documents_with_existing_ids() calls 2 function(s): _sort_by_id, has_get_by_ids.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free