Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ packages:
js: "@langchain/deepseek"
downloads: 697000
downloads_updated_at: "2026-05-18T00:23:32.797657+00:00"
- name: langchain-engram
repo: Harshitk-cp/langchain-engram
downloads: 0
downloads_updated_at: "2026-05-29T00:00:00.000000+00:00"
- name: langchain-exa
repo: langchain-ai/langchain
path: libs/partners/exa
Expand Down
8 changes: 8 additions & 0 deletions src/oss/python/integrations/providers/all_providers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ Browse the complete collection of integrations available for Python. LangChain P
Cloud content collaboration and AI-powered search platform.
</Card>

<Card
title="Engram"
href="/oss/integrations/providers/engram"
icon="link"
>
Cognitive memory infrastructure for AI agents — confidence scoring, contradiction detection, and memory lifecycle.
</Card>

<Card
title="Elasticsearch"
href="/oss/integrations/providers/elasticsearch"
Expand Down
41 changes: 41 additions & 0 deletions src/oss/python/integrations/providers/engram.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "Engram integrations"
description: "Integrate with Engram using LangChain Python."
---

[Engram](https://engram.ai) is cognitive memory infrastructure for AI agents.
Engram tracks **confidence scores**, detects **contradictions**, and manages
**memory lifecycle**—so agents know what they know and when to doubt it.

Key capabilities:
- 4-type cognitive model: semantic, episodic, procedural, and working memory
- Calibrated confidence scoring with Bayesian log-odds updates
- Contradiction detection with automatic belief reconciliation
- Hybrid vector + knowledge-graph retrieval (pgvector + graph traversal)
- Memory decay: stale beliefs lose confidence over time

## Installation and setup

<CodeGroup>
```bash pip
pip install langchain-engram
```

```bash uv
uv add langchain-engram
```
</CodeGroup>

Set environment variables:

```bash
export ENGRAM_BASE_URL=http://localhost:8080
export ENGRAM_API_KEY=mk_...
```

See the [Engram quickstart](https://engram.ai#quickstart) for server setup.

## Retrievers

See the [EngramRetriever documentation](/oss/integrations/retrievers/engram) for
memory-backed retrieval with confidence filtering and hybrid recall.
118 changes: 118 additions & 0 deletions src/oss/python/integrations/retrievers/engram.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: "Engram retriever"
description: "Integrate with the Engram retriever using LangChain Python."
---

# EngramRetriever

This will help you get started with the Engram [retriever](/oss/langchain/retrieval).

Engram is cognitive memory infrastructure for AI agents—tracking not just what
agents know, but how confident they should be, and when to doubt it. Each retrieved
memory is a `Document` carrying confidence score, memory tier, and relevance scores
from Engram's hybrid vector + knowledge-graph recall.

### Integration details

| Retriever | Self-host | Cloud offering | Package |
| :--- | :---: | :---: | :---: |
| `EngramRetriever` | ✅ | ✅ | `langchain-engram` |

## Setup

### Installation

```bash
pip install langchain-engram
```

### Start the server

```bash
git clone https://github.com/Harshitk-cp/engram.git
cd engram
ENGRAM_SETUP_TOKEN=changeme docker compose up -d

# Get your API key (run once)
curl -X POST http://localhost:8080/v1/setup \
-H "X-Setup-Token: changeme" \
-H "Content-Type: application/json" \
-d '{"org_name": "My Org"}'
# → {"api_key": "mk_..."}
```

### Environment variables

```bash
export ENGRAM_BASE_URL=http://localhost:8080
export ENGRAM_API_KEY=mk_...
```

## Instantiation

```python
from langchain_engram import EngramRetriever

retriever = EngramRetriever(
agent_id="your-agent-uuid",
# api_key and base_url read from env if not passed
top_k=5,
min_confidence=0.6, # only surface confident memories
)
```

## Usage

```python
docs = retriever.invoke("display preferences")
for doc in docs:
print(doc.page_content)
print(f" confidence: {doc.metadata['confidence']:.0%}")
print(f" tier: {doc.metadata['tier']}") # hot / warm / cold
print(f" type: {doc.metadata['memory_type']}") # fact / preference / decision
print(f" score: {doc.metadata.get('score', 'n/a')}")
```

### In a RetrievalQA chain

```python
from langchain.chains import RetrievalQA
from langchain_openai import ChatOpenAI

qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(), retriever=retriever)
answer = qa.invoke({"query": "What are the user's display preferences?"})
```

### Document metadata fields

| Field | Type | Description |
| :--- | :--- | :--- |
| `memory_id` | `str` | UUID of the memory |
| `agent_id` | `str` | Owning agent UUID |
| `memory_type` | `str` | `fact` / `preference` / `decision` / `constraint` |
| `confidence` | `float` | Calibrated confidence score (0–1) |
| `tier` | `str` | `hot` / `warm` / `cold` |
| `source` | `str` | Origin of the memory |
| `score` | `float` | Combined recall score |
| `vector_score` | `float` | Vector similarity component |
| `graph_score` | `float` | Graph traversal component |
| `created_at` | `str` | ISO 8601 timestamp |

## Configuration

| Parameter | Default | Description |
| :--- | :--- | :--- |
| `agent_id` | required | Engram agent UUID |
| `api_key` | `ENGRAM_API_KEY` env | `mk_` or `rk_` prefixed API key |
| `base_url` | `ENGRAM_BASE_URL` env | Engram server URL |
| `top_k` | `10` | Max memories to return |
| `min_confidence` | `None` | Confidence floor (0–1) |
| `memory_type` | `None` | Filter by type: `fact`, `preference`, `decision`, `constraint` |
| `graph_weight` | `None` | Graph/vector blend (0–1); server default 0.4/0.6 |

## Related links

- [Engram documentation](https://engram.ai)
- [Python SDK (engram.to)](https://pypi.org/project/engram.to/)
- [GitHub](https://github.com/Harshitk-cp/langchain-engram)
- [Provider page](/oss/integrations/providers/engram)
1 change: 1 addition & 0 deletions src/oss/python/integrations/retrievers/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The below retrievers will search over an external index (e.g., constructed from
<Card title="Dappier" icon="link" href="/oss/integrations/retrievers/dappier" arrow="true" cta="View guide" />
<Card title="Elasticsearch" icon="link" href="/oss/integrations/retrievers/elasticsearch_retriever" arrow="true" cta="View guide" />
<Card title="Egnyte" icon="link" href="/oss/integrations/retrievers/egnyte" arrow="true" cta="View guide" />
<Card title="Engram" icon="link" href="/oss/integrations/retrievers/engram" arrow="true" cta="View guide" />
<Card title="Galaxia" icon="link" href="/oss/integrations/retrievers/galaxia-retriever" arrow="true" cta="View guide" />
<Card title="Google Drive" icon="link" href="/oss/integrations/retrievers/google_drive" arrow="true" cta="View guide" />
<Card title="Google Vertex AI Search" icon="link" href="/oss/integrations/retrievers/google_vertex_ai_search" arrow="true" cta="View guide" />
Expand Down
Loading