How to Add Memory to ChatWise: Buffer, Summary, Vector

GT

GigaRAG team

Retrieval13 min read
On this page
Developer hands beside a laptop showing Python code for appending conversation history, with index cards labeled Buffer, Summary, and Vector Store arranged on a desk to illustrate memory approaches for GigaRAG's ChatWise guide.
Developer hands beside a laptop showing Python code for appending conversation history, with index cards labeled Buffer, Summary, and Vector Store arranged on a desk to illustrate memory approaches for GigaRAG's ChatWise guide.

How to Add Memory to ChatWise

Adding memory to ChatWise stumps most developers for one simple reason: the API is stateless, so every call starts fresh. You send a prompt, you get a response, and the conversation history vanishes. If you're building an agent or a RAG pipeline, that's not a limitation you can code around with a clever prompt. Most tutorials don't help either. They assume you're using LangChain, or they push a specific vendor's memory layer and leave you locked in. The honest answer is that ChatWise doesn't ship with memory, and it won't add it for you. You have to build it. GigaRAG can simplify the agent memory and RAG integration side of that work, but you still need to understand the underlying patterns first. This guide covers three framework-agnostic approaches to how to add memory to ChatWise: a conversation buffer, summary memory, and a vector store for semantic recall. Each one comes with real trade-offs, and you'll leave with code you can adapt to your own stack.

At a glanceDetails
Native memoryChatWise has no built-in memory
Core approachesBuffer, summary, vector store
Best for agentsVector store + retrieval
Key limitationStateless API resets each request
Implementation effortModerate; requires external store
Framework lock-inNone; works with any stack

In This Guide

What Memory Means for ChatWise

Memory in a ChatWise chat app is any state you explicitly store and re-inject into later API calls. ChatWise doesn't keep it for you. You do.

Short-term vs. long-term memory

Short-term memory is the conversation buffer: the last few turns you append to each prompt so the model knows what was just said. It lives in your application's runtime, resets when the process restarts, and costs tokens every call.

Long-term memory is anything you persist outside the request: a database row, a summary file, a vector store. You retrieve it when relevant, not every time. It survives restarts and scales past the context window.

Why ChatWise is stateless by default

Every ChatWise API request is independent. The server processes your prompt, returns a response, and forgets the exchange. Nothing about the previous call exists on ChatWise's side.

That's not a flaw. It's how most LLM APIs work. The trade-off is yours to manage: you get full control over what gets remembered, but you also get full responsibility for building it.

[!note] ChatWise does not provide built-in memory; any memory implementation must be handled externally by your application. This means you are responsible for storing, retrieving, and injecting conversation history.

Buffer Memory vs Vector Store Memory for ChatWise

FactorBuffer MemoryVector Store Memory
Implementation complexityLow: store messages in a listModerate: embed, index, retrieve
Context window usageGrows linearly; may exceed limitsFixed: only top-k relevant chunks
Recall of past detailsExact but limited to recent turnsSemantic; can recall older relevant info
Best forShort chats, prototypingLong conversations, agent memory, RAG
PersistenceIn-memory or simple DBVector DB (e.g., Pinecone, Chroma)

Prerequisites for Adding Memory to ChatWise

Before you write any memory code, you need three things in place. Skip one and you'll stall mid-build.

ChatWise API credentials

You need a working API key and a confirmed endpoint. Test a bare request first: send a single prompt, get a response. If that fails, memory won't save you. Keep the key out of client-side code.

Choosing a storage backend

Buffer memory needs nothing more than a list in your app's runtime. Summary and vector memory need somewhere persistent. A Postgres table works for summaries. A vector store (Pinecone, Weaviate, pgvector) works for embeddings. Pick based on whether you're retrieving by recency or by meaning.

Embedding model basics (for vector memory)

Vector memory stores text as numbers. You need an embedding model to convert conversation turns into vectors, and you need to use the same model for both writing and querying. Mixing models breaks similarity search.

[!tip] For agent memory, combine buffer and vector store: keep the last few turns in a buffer for immediate context, and use vector retrieval for older relevant information. This hybrid approach balances recency and relevance without blowing up your context window.

How To Add Memory To ChatWise: A Step-by-Step Guide

  1. Choose a memory strategy: buffer for short-term, vector store for long-term.
  2. Set up an external store (e.g., Redis for buffer, Chroma for vectors).
  3. On each user message, retrieve relevant history from the store.
  4. Construct the prompt by injecting retrieved history into the system or user message.
  5. Send the augmented prompt to ChatWise's API and get the response.
  6. Store the new user message and assistant response back into the store.
  7. For vector memory, embed messages and upsert into the vector database.
Numbered cards showing seven steps to add memory to ChatWise, from choosing a memory strategy and setting up an external store to retrieving history, constructing prompts, and upserting vectors, based on GigaRAG's guide.

Step 1: Implement a Conversation Buffer

A conversation buffer is the simplest memory you can add. It's just a list that holds every user message and assistant response, in order. Before each ChatWise API call, you prepend that list to the prompt. The model sees the full history and responds as if it remembers.

How a buffer works

You keep two things in sync: the buffer itself and the prompt you build from it. When the user sends a message, you append it to the buffer. When ChatWise returns a response, you append that too. Next request, you join the buffer into a single string and pass it as context. That's the whole mechanic.

The catch is growth. Every turn adds tokens. A 20-turn conversation can easily hit 3,000 tokens before the new prompt even starts. You'll hit the model's context window fast, so a buffer alone only works for short sessions.

Code example: appending and injecting history

Here's a minimal Python pattern. No framework required.

history = []

def chat(user_input):
    history.append({"role": "user", "content": user_input})
    
    context = "\n".join(
        f"{turn['role']}: {turn['content']}" for turn in history
    )
    
    prompt = f"{context}\nassistant:"
    
    # Call ChatWise API with prompt
    response = call_chatwise(prompt)
    
    history.append({"role": "assistant", "content": response})
    return response

Each call rebuilds the prompt from the full history. It's inefficient at scale, but it's transparent and easy to debug. You can see exactly what the model saw.

Token limit considerations

You need a hard cap. Count tokens on each append, and when the buffer exceeds your limit (say 3,000 tokens for a 4,096-token window), drop the oldest turns first. Don't silently truncate mid-message. Log what you removed so you can debug context loss later.

A buffer won't survive a server restart unless you persist it. For anything longer than a single session, you'll need the summary approach in the next step.

Step 2: Add Summary Memory for Long Conversations

A buffer works until it doesn't. The fix is summary memory: you compress older turns into a short paragraph, store that, and drop the raw messages. You keep the gist without the token bill.

When buffer memory breaks down

The buffer approach fails in two ways. First, token limits. A 50-turn conversation blows past any context window, and dropping oldest turns means losing early context that might matter. Second, cost. Every API call re-sends the full history, so you pay for the same tokens over and over.

Summary memory trades fidelity for efficiency. You lose exact wording and fine detail. You keep the topics, decisions, and constraints. For most support chats and agent tasks, that's the right trade.

Generating and storing summaries

You generate the summary with a separate LLM call. Don't summarize on every turn. Wait until the buffer hits a threshold, say 10 turns or 2,000 tokens, then compress everything older than the last few turns.

Here's the pattern:

def summarize(history):
    prompt = f"Summarize this conversation in under 150 words, keeping key facts, decisions, and user preferences:\n\n{history}"
    return call_llm(prompt)

if len(history) > 10:
    summary = summarize(history[:-4])  # keep last 4 turns raw
    history = [{"role": "summary", "content": summary}] + history[-4:]

Store the summary in your database alongside the session ID. On the next request, load it and prepend it to the prompt before the recent turns.

Combining buffer and summary

You don't choose one or the other. You run both. The summary holds the long arc. The buffer holds the last few turns verbatim. The model gets recent detail plus compressed context.

The honest catch: summaries drift. Each new summary is built from the previous one plus new turns, so errors compound. Re-summarize from raw history periodically if you can afford the storage. And keep the summary short. A 500-word summary defeats the purpose.

Step 3: Use a Vector Store for Semantic Memory

Summary memory keeps the gist. Vector memory keeps the meaning. You store conversation turns or knowledge snippets as embeddings, then retrieve whatever is semantically closest to the current query. The model gets relevant context without you deciding in advance what matters.

Embedding conversation turns

An embedding is a list of numbers that represents what a piece of text means. Similar text gets similar numbers. You run each turn through an embedding model, then store the vector alongside the raw text in a vector database like Pinecone, Weaviate, or pgvector.

Here's the pattern:

def store_turn(session_id, text, role):
    vector = embed(text)  # returns a list of floats
    db.insert(
        session_id=session_id,
        vector=vector,
        text=text,
        role=role,
        timestamp=now()
    )

You don't store every turn forever. Filter by session, and prune old or low-relevance vectors on a schedule. Storage costs are real.

Retrieving relevant memories

On each new request, embed the user's message, then query the vector store for the top 3 to 5 nearest vectors from that session. Inject the returned text into the prompt before the current turn.

def get_memories(session_id, query, k=4):
    query_vector = embed(query)
    results = db.search(
        session_id=session_id,
        vector=query_vector,
        limit=k
    )
    return [r.text for r in results]

The honest catch: retrieval is only as good as your embedding model. If the user asks about "the invoice from March" and your embeddings don't capture date references well, you'll pull the wrong memory. Test retrieval quality on real conversations before trusting it.

Integrating with RAG pipelines

This is where vector memory earns its keep. A RAG pipeline already has a vector store for documents. You can store conversation turns in the same database, tagged with a session ID, and retrieve both document chunks and past turns in one query.

For agents, vector memory means the agent can recall a user preference from three sessions ago without you hardcoding a lookup. The agent embeds its current task, retrieves relevant past context, and acts on it.

The main catch: you now maintain two retrieval paths. Document retrieval needs broad coverage. Memory retrieval needs session scoping and recency weighting. Don't merge them blindly. Keep session ID as a filter on every memory query, or you'll leak context across users.

Common Mistakes When Adding Memory to ChatWise

Memory is easy to bolt on and easy to get wrong. Most failures come from three places.

Ignoring token limits

A buffer that grows forever will blow past your context window. The model then drops the oldest turns silently, or the API rejects the request outright. You won't get an error telling you memory was lost. Cap the buffer by token count, not message count. Check your model's limit and subtract room for the system prompt and the response.

Storing raw text without structure

Raw text in a database is not memory. It's a log. Without embeddings, timestamps, or session IDs, you can't retrieve anything relevant. You can only dump the whole thing back into the prompt, which recreates the token problem. Structure every stored turn with at least a session ID and a timestamp. Add embeddings if you want semantic recall.

Forgetting to prune old memories

Memory rots. Old turns go stale, user preferences change, and irrelevant context pollutes retrieval. If you never prune, your vector store fills with noise and your summaries drift. Schedule cleanup. Delete turns older than a threshold, or drop low-relevance vectors on a fixed interval. Memory needs maintenance, not just storage.

What Not to Expect from ChatWise Memory

ChatWise does not ship with built-in memory. The API is stateless, and no configuration flag turns on persistence. You build it yourself, or you don't have it.

Memory does not make the model remember in a human sense. The model has no internal state between requests. What you're doing is feeding it context it has seen before. If that context is wrong, stale, or incomplete, the model will confidently build on it anyway.

Vector store memory is not set-and-forget. Embeddings drift as your data changes. Old entries need pruning. Retrieval quality degrades without regular maintenance. Budget for that work, or your memory will quietly become noise.

Don't expect memory to fix a bad prompt. If the model gives poor answers without history, it will give poor answers with history attached.

Final Thoughts

Start with the buffer. It's the fastest way to add memory to ChatWise, and it handles most short conversations without extra infrastructure. When token limits bite, add summary memory on top. When you need semantic recall across many sessions, move to a vector store.

Agent and RAG pipeline builders will hit the vector store path sooner than most. That's where the real work lives: embedding turns, tuning retrieval, pruning stale entries.

If you'd rather not build the plumbing yourself, GigaRAG handles agent memory and RAG pipeline integration in one pass. It won't make ChatWise stateful, but it removes most of the manual wiring from how to add memory to ChatWise.

Frequently Asked Questions

Does ChatWise have built-in memory?

No, ChatWise does not include native memory features. Its API is stateless, so each request is independent. You must implement memory externally using your own storage and retrieval logic.

How do I add memory to ChatWise?

You add memory by storing conversation history in an external store (like a database or vector store) and injecting relevant parts into the prompt before sending it to ChatWise. This can be as simple as a buffer of recent messages or as advanced as semantic retrieval.

What is the best memory approach for ChatWise agents?

For agents, a vector store memory is often best because it allows semantic retrieval of relevant past interactions, which is crucial for long-running tasks. However, a hybrid approach with a buffer for recent turns can improve coherence.

Can I use ChatWise with RAG pipelines?

Yes, ChatWise can be integrated into RAG pipelines. You can use a vector store to retrieve relevant documents or past conversation snippets and include them in the prompt sent to ChatWise.

How do I persist memory across sessions in ChatWise?

Persist memory by using a durable external store such as a database (SQL or NoSQL) or a vector database. Store each message with a session ID, and retrieve by session ID on subsequent requests.

What are the limitations of adding memory to ChatWise?

Limitations include increased latency from retrieval, potential context window overflow if not managed, and the need to handle embedding costs for vector memory. Also, memory quality depends on your retrieval strategy.

About GigaRAG

GigaRAG is for agent memory and RAG pipeline builders. get this right. Whether you are working through How to add memory to ChatWise or something adjacent, we publish what we have actually tested, including where it falls short.

All posts