Skip to main content

langchain-taguru (Python)

Official LangChain integration for the Taguru long-term semantic memory server. The TypeScript twin (langchain-taguru on npm) exposes the identical surface.

pip install langchain-taguru
from langchain_openai import ChatOpenAI
from taguru_langchain import TaguruIngester, TaguruRetriever

# Write: an LLM decomposes documents into the association graph
# (the LangChain twin of `taguru extract`; per-source replace, idempotent).
ingester = TaguruIngester(
    context="sake",
    llm=ChatOpenAI(model="gpt-4.1", temperature=0),
    create_context=True,
    context_description="青嶺酒造という架空の酒蔵の知識",
)
ingester.ingest_documents(docs)          # docs[*].metadata["source"] required

# Read: graph lane (resolve → activate → citations) + text lane
# (search_passages), merged by Reciprocal Rank Fusion.
retriever = TaguruRetriever(context="sake", k=8)
documents = retriever.invoke("青嶺酒造")

Runnable use-case examples (RAG QA with citations, governed ingestion, conversational long-term memory — each mirrored in TypeScript) live in examples/langchain; they work offline, no API key needed.

TaguruIngester takes an optional on_event callback for live progress — document/chunk/attempt/import/embedding-refresh events, including why a corrective attempt fired. Useful with slow local models, where a single ingest_text() call can otherwise look like one long silent block:

ingester = TaguruIngester(..., on_event=lambda event: print(event.kind))

Checkpoint/resume for spot and preemptible instances

Pass checkpoint_store to survive an interruption mid-document (a killed process, a reclaimed spot instance) without losing every chunk already extracted for it:

from taguru_langchain import FilesystemCheckpointStore

ingester = TaguruIngester(
    ...,
    checkpoint_store=FilesystemCheckpointStore(".taguru-checkpoints"),
)

Each chunk's accepted output is durably persisted (keyed by the chunk's own content hash) before the next chunk starts; rerunning the same ingest_text()/ingest_documents() call after an interruption resumes without re-calling the model for chunks already completed. Changing the document's content, the model, or any output-shaping setting (fact_budget, structured_output, questions, ...) invalidates the whole cache rather than risking a silent reuse of an incompatible output. The checkpoint is cleared once the document's batch actually lands in /import, and kept if the document ultimately fails — so a dry_run=True call, which never imports, still records checkpoints but never deletes them. Pass should_stop (a zero-argument callable, or a threading.Event) to stop cooperatively between chunks; IngestOutcome.interrupted reports whether that happened.

checkpoint_store accepts anything implementing the three-method CheckpointStore protocol (load/save/delete, keyed by source id), so object storage or a database work as a drop-in replacement for FilesystemCheckpointStore on an ephemeral instance with no durable local disk:

class S3CheckpointStore:
    def load(self, source: str) -> bytes | None: ...
    def save(self, source: str, data: bytes) -> None: ...  # must be atomic
    def delete(self, source: str) -> None: ...

To force a full re-extraction ignoring whatever is cached, delete that source's checkpoint yourself — store.delete(source), or FilesystemCheckpointStore.path_for(source).unlink().

For composing this with a bounded, resumable runner (time/item windows, signal handling, torn-import repair), see long-running ingestion.

Three more constructor arguments bound how a chunk's structured-output retry behaves, all optional and all unchanged by default: fact_budget asks the model to keep a chunk's answer to at most N associations; max_attempts (default 2, 1-10) raises or lowers the total attempts at valid JSON per chunk before the document fails; and corrective_context_bytes caps how much of a malformed answer gets replayed back on the next attempt (0 omits it behind a placeholder; left unset, the default, replays it in full). Worth raising max_attempts or setting fact_budget/corrective_context_bytes on slow local models, where a large malformed answer near the output cap can otherwise stall a chunk for minutes.

TaguruIngester also takes an optional structured_output flag (default False) that asks the chat model for JSON-schema-constrained generation — llm.with_structured_output(MODEL_OUTPUT_JSON_SCHEMA, include_raw=True) — instead of parsing a free-text answer. Strictly opt-in and provider/model dependent: a chat model that cannot bind tools raises out of the constructor immediately, before any document is ingested, rather than surfacing later as a per-attempt failure. Either way the answer still goes through the same lenient validation walk and business-rule checks a free-text answer gets — a schema only narrows what shape a well-behaved provider can return.

By default, a business-rule-invalid item (a bad weight, a dangling alias, an out-of-range question, ...) never gets silently dropped and reported as a success: it earns one targeted, path-addressed corrective turn naming exactly which fields are wrong, and the source fails outright (no /import call) if it's still invalid afterward. Pass lossy=True to restore the old drop-and-proceed behavior instead — the source still imports, and IngestOutcome.invalid_dropped counts what got silently discarded.

Not provided, deliberately: a VectorStore facade (Taguru's retrieval is structural-first — similarity_search would misrepresent it), a Memory class (deprecated upstream in favor of LangGraph state), and agent Tools (the MCP bridge taguru-mcp already serves the identical tools; pair it with langchain-mcp-adapters).

The behavioral contract is the server's protocol document (GET /protocol); the ingestion prompt/validation mirror taguru extract (PROMPT_VERSION is kept in sync with src/extract.rs).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_taguru-0.5.0.tar.gz (249.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_taguru-0.5.0-py3-none-any.whl (50.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_taguru-0.5.0.tar.gz.

File metadata

  • Download URL: langchain_taguru-0.5.0.tar.gz
  • Upload date:
  • Size: 249.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for langchain_taguru-0.5.0.tar.gz
Algorithm Hash digest
SHA256 403820058185ecde94534e539f8bb474857f40bb9360916f068a6092c554077b
MD5 4b286b4169fdebea476517c80efe1263
BLAKE2b-256 ecfb6ef31e7e97b248e0d10bccb730df3c70016a33249c86a938a0971dcaebce

See more details on using hashes here.

File details

Details for the file langchain_taguru-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_taguru-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dbb6bbebc6930ca3ad78873761f5d316e89b3cbd87f69cdd11ae47deab7c4614
MD5 495b80f83169630491f2b49e0ea09d3a
BLAKE2b-256 00594b1a1537b24a832802625b8cd883373b29dcd7928342dd91d4dfdf7984b8

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page