Library for LangChain documents
Actively maintained. Last release 4 months ago, commits in 15 of the last 26 weeks. A safe choice.
pip install docculusLibrary for LangChain documents
Actively maintained. Last release 4 months ago, commits in 15 of the last 26 weeks. A safe choice.
pip install docculusdocculus is a lightweight Python library that makes it easy to analyze, transform, hash, and
validate
langchain_core.documents.Document
objects.
Quick Links:
Working with collections of LangChain documents often means writing the same boilerplate over and
over: counting duplicates, filtering by metadata, formatting documents into an LLM-friendly
prompt, or hashing content to detect changes. docculus packages these operations into a small,
well-tested API:
Deduplicate and format documents for a prompt:
>>> from langchain_core.documents import Document
>>> from docculus.transform import deduplicate_documents, format_documents
>>> docs = [
... Document(id="1", page_content="The cat sat on the mat."),
... Document(id="2", page_content="The cat sat on the mat."),
... Document(id="3", page_content="The dog chased the ball."),
... ]
>>> unique_docs = deduplicate_documents(docs)
>>> print(format_documents(unique_docs, output_format="markdown"))
## Document 1
<BLANKLINE>
The cat sat on the mat.
<BLANKLINE>
## Document 2
<BLANKLINE>
The cat sat on the mat.
<BLANKLINE>
## Document 3
<BLANKLINE>
The dog chased the ball.
Inspect a corpus at a glance:
>>> from docculus.analysis import compute_content_stats_exact
>>> stats = compute_content_stats_exact(docs)
>>> stats["count"], stats["duplicate_count"]
(3, 1)
Check consistency across documents sharing an id:
>>> from docculus.validation import validate_document_consistency
>>> validate_document_consistency(docs)
True
docculus provides a comprehensive set of utilities for working with Document objects:
Corpus-wide, read-only inspection utilities:
compute_content_stats_exact() and
compute_content_stats_approx()compute_metadata_stats()find_duplicate_document_ids(),
find_empty_documents(), and find_empty_document_ids()print_content_stats_report() and
print_metadata_stats_report()Utilities that produce a new document list:
deduplicate_documents()filter_by_metadata(), filter_by_metadata_range(), and
filter_by_metadata_values()sort_by_metadata() and truncate with truncate_documents()assign_ids() and copy_ids_to_metadata()format_documents()Per-document utilities:
generate_id(), generate_random_id(), and generate_deterministic_id()is_empty() and is_whitespace_only()get_length(), get_lengths(), get_longest_document(), and
get_shortest_document()Deterministic hashing of documents:
hash_document() and hash_documents()hash_document_to_uuid()register_document_hasher()Consistency checks across documents sharing an id, via validate_document_consistency().
Pretty-print documents and their metadata to the terminal with print_document(),
print_documents(), and print_documents_metadata().
Persist and retrieve documents with a common BaseDocumentStore interface, with
InMemoryDocumentStore, SQLiteDocumentStore, and DuckDBDocumentStore implementations
(plus typed variants).
We highly recommend installing
docculus in
a virtual environment
to avoid dependency conflicts.
uv is a fast Python package installer and resolver:
uv pip install docculus
Install with all optional dependencies:
uv pip install docculus[all]
Install with specific optional dependencies:
uv pip install docculus[duckdb,rich] # with DuckDB and rich
Alternatively, you can use pip:
pip install docculus
Install with all optional dependencies:
pip install docculus[all]
coola | coola | langchain-core | duckdb* | faker* | persista* | rich* | python |
|---|---|---|---|---|---|---|---|
main | >=1.1.10,<1.0 | >=1.4,<2.0 | >=1.3,<2.0 | >=40.0,<41.0 | >=0.0.3,<1.0 | >=14.0.0,<16.0 | >=3.10 |
0.0.1 | >=1.1.10,<1.0 | >=1.4,<2.0 | >=1.3,<2.0 | >=40.0,<41.0 | >=0.0.3,<1.0 | >=14.0.0,<16.0 | >=3.10 |
* indicates an optional dependency
Contributions are welcome! We appreciate bug fixes, feature additions, documentation improvements, and more. Please check the contributing guidelines for details on:
Whether you're fixing a bug or proposing a new feature, please open an issue first to discuss your changes.
:warning: Important: As docculus is under active development, its API is not yet stable and
may
change between releases. We recommend pinning a specific version in your project’s dependencies to
ensure consistent behavior.
docculus is licensed under BSD 3-Clause "New" or "Revised" license available in LICENSE
file.
Use together with docculus: extensions, drivers, servers and companion tools.