@khareindustries/synapse-sdk
v0.1.3
Published
JavaScript SDK for Synapse memory infrastructure
Downloads
485
Maintainers
Readme
README.md
Synapse currently focuses on self-hosted and developer-operated memory infrastructure for AI applications.
Why Synapse?
Most AI applications still forget users between conversations.
Developers often need to manually build:
- embedding pipelines
- vector databases
- semantic retrieval systems
- reranking
- memory persistence
- context injection
- long-term memory orchestration
Synapse provides a unified memory infrastructure layer for AI systems.
The goal is to make persistent AI memory:
- scalable
- developer-friendly
- composable
- production-ready
- low-latency
Automatic Memory Injection
const openai = synapse.wrap(
new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
}),
{
namespace: "medical-app",
userId: "user-123",
}
);
await openai.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "user",
content: "my stomach hurts",
},
],
});Synapse automatically:
- retrieves relevant memories
- formats memory context
- injects context into prompts
- ingests assistant responses
- persists long-term memory
No manual prompt engineering required.
Demo
🎥 Full introduction video coming soon.
Features
| Feature | Status | | ----------------------------- | ------ | | Semantic memory retrieval | ✅ | | Long-term memory storage | ✅ | | Redis working memory | ✅ | | Vector retrieval | ✅ | | Reranking pipelines | ✅ | | Prompt-ready context building | ✅ | | Automatic message injection | ✅ | | AI client wrapping | ✅ | | Memory update APIs | ✅ | | Memory deletion APIs | ✅ | | TypeScript SDK | ✅ | | API authentication | ✅ | | Self-hosted architecture | ✅ | | Hosted Synapse Cloud | 🚧 | | LangChain integration | 🚧 | | OpenAI Agents SDK integration | 🚧 | | Vercel AI SDK integration | 🚧 | | Dashboard & analytics | 🚧 |
Architecture
Synapse combines:
- semantic embeddings
- vector search
- reranking pipelines
- Redis working memory
- long-term vector storage
- retrieval optimization
- memory orchestration
to provide persistent contextual memory for AI systems.
Memory Pipeline
retrieve()
↓
buildContext()
↓
inject()
↓
wrap()Synapse is designed around composable memory primitives.
Developers can:
- use low-level retrieval APIs
- inject memory manually
- or fully automate memory workflows using wrap()
Installation
npm install @khareindustries/synapse-sdkQuick Start
import {
createSynapseClient,
} from "@khareindustries/synapse-sdk";
const synapse = createSynapseClient({
apiUrl: "http://localhost:3000/api/developer",
apiKey: process.env.SYNAPSE_API_KEY,
});
async function main() {
await synapse.ingest({
namespace: "career-coach-app",
userId: "user-123",
source: "chat",
content:
"I am preparing for React Native interviews and targeting Bangalore startups.",
metadata: {
app: "career-coach",
sessionId: "sess_abc123",
},
});
const memory =
await synapse.retrieve({
namespace: "career-coach-app",
userId: "user-123",
query: "Help optimize my resume",
});
console.log(memory.summary);
console.log(memory.memories);
}
main();More local examples live in sdk/examples/:
basic.tsfor direct ingest/retrieve usageopenai-wrap.tsfor automatic OpenAI chat memory injectionclaude-wrap.tsfor Anthropic Claude message wrappinggemini-wrap.tsfor Google Gemini content generation wrapping
Core APIs
createSynapseClient()
Creates a Synapse SDK client.
const synapse = createSynapseClient({
apiUrl: string,
apiKey?: string,
timeout?: number,
});| Option | Type | Required | Description | | ------- | ------ | -------- | ------------------------------- | | apiUrl | string | Yes | Synapse server URL | | apiKey | string | No | API authentication key | | timeout | number | No | Request timeout in milliseconds |
synapse.ingest()
Stores memories into Synapse.
await synapse.ingest({
namespace: "app-name",
userId: "user-123",
content: "User likes React Native",
});synapse.retrieve()
Retrieves relevant memories semantically.
const result =
await synapse.retrieve({
namespace: "app-name",
userId: "user-123",
query: "What technologies does user like?",
});synapse.buildContext()
Formats retrieved memories into a prompt-ready string.
const context =
await synapse.buildContext({
namespace: "medical-app",
userId: "user-123",
query: "my stomach hurts",
maxTokens: 120,
});synapse.inject()
Injects memory context into an OpenAI-style messages array.
const messages =
await synapse.inject({
namespace: "medical-app",
userId: "user-123",
messages: [
{
role: "user",
content: "my stomach hurts",
},
],
});synapse.wrap()
Wraps OpenAI and Anthropic clients with automatic memory orchestration.
const openai = synapse.wrap(
new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
}),
{
namespace: "medical-app",
userId: "user-123",
}
);
await openai.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "user",
content: "my stomach hurts",
},
],
});Supported wrapped methods:
- openai.chat.completions.create(...)
- anthropic.messages.create(...)
After responses return, Synapse automatically ingests assistant messages into long-term memory.
Provider Helpers
For explicit provider integrations, Synapse also exposes dedicated wrappers:
const openai = synapse.wrapOpenAI(client, options);
const claude = synapse.wrapClaude(client, options);
const anthropic = synapse.wrapAnthropic(client, options);
const gemini = synapse.wrapGemini(client, options);Current provider method support:
wrapOpenAI()wrapschat.completions.create(...)wrapClaude()andwrapAnthropic()wrapmessages.create(...)wrapGemini()wrapsmodels.generateContent(...)
synapse.updateMemory()
Updates an existing memory.
await synapse.updateMemory({
namespace: "app-name",
userId: "user-123",
memoryId: "mem_123",
text: "User prefers React Native with Expo",
});synapse.deleteMemory()
Deletes an outdated or incorrect memory.
await synapse.deleteMemory({
namespace: "app-name",
userId: "user-123",
memoryId: "mem_123",
});Example Response
{
"success": true,
"summary": "User is preparing for React Native interviews.",
"memories": [
{
"id": "mem_123",
"text": "User is preparing for React Native interviews.",
"category": "career",
"importance": 0.92
}
]
}Error Handling
try {
await synapse.retrieve({
namespace: "app",
userId: "123",
query: "React Native",
});
} catch (error) {
console.error(error);
}Requirements
- Node.js 18+
- Running Synapse backend server
Roadmap
- [x] Semantic retrieval
- [x] TypeScript SDK
- [x] Local infrastructure
- [x] Prompt-ready context building
- [x] Automatic memory injection
- [x] AI client wrapping
- [x] Memory update APIs
- [x] Memory deletion APIs
- [ ] Hosted Synapse Cloud
- [ ] Streaming retrieval
- [ ] LangChain integration
- [ ] Vercel AI SDK integration
- [ ] Memory importance scoring
- [ ] Structured memory extraction
- [ ] Memory observability & debugging
- [ ] Dashboard & analytics
- [ ] Multi-agent memory systems
- [ ] Agent memory graphs
- [ ] Memory visualization tools
Community
License
MIT License
