# How do you manage your context tokens for RAG?

**URL:** https://community.openai.com/t/how-do-you-manage-your-context-tokens-for-rag/655695
**Category:** API
**Tags:** rag
**Created:** [February 26, 2024, 5:53pm UTC](https://community.openai.com/t/how-do-you-manage-your-context-tokens-for-rag/655695 "2024-02-26T17:53:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![APRO](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/apro/32/512393_2.png) [@APRO](https://community.openai.com/u/APRO)
#### Post date: [February 26, 2024, 5:53pm UTC](https://community.openai.com/t/how-do-you-manage-your-context-tokens-for-rag/655695/1 "2024-02-26T17:53:01Z")

</div>

Hey everyone,

Apologies in advance as I am a “beginner” in this field.

I’ve created a chatbot for Q&A about an uploaded file (pdf slides) using embeddings and RAG. However I always reach my token limit (either TPM or context) as when I ask the chatbot multiple questions I simply have to much tokens in my chat history due to multiple RAGs. How did you do it without deleting the “oldest” message in chat history? And how do you manage your context window in a conversation/thread?

---

<div class="post-metadata">

### Author: ![sps](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sps/32/7736_2.png) [@sps](https://community.openai.com/u/sps)
#### Post date: [February 26, 2024, 11:09pm UTC](https://community.openai.com/t/how-do-you-manage-your-context-tokens-for-rag/655695/2 "2024-02-26T23:09:51Z")

</div>

Hi @APRO

Context tokens can be managed using [embeddings](https://platform.openai.com/docs/guides/embeddings/embeddings).

I wrote a tutorial for simple context management last year: [Use embeddings to retrieve relevant context for AI assistant](https://community.openai.com/t/use-embeddings-to-retrieve-relevant-context-for-ai-assistant/268538)

---

<div class="post-metadata">

### Author: ![APRO](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/apro/32/512393_2.png) [@APRO](https://community.openai.com/u/APRO)
#### Post date: [February 27, 2024, 9:18am UTC](https://community.openai.com/t/how-do-you-manage-your-context-tokens-for-rag/655695/3 "2024-02-27T09:18:19Z")

</div>

Thank you so much!! This is perfect 😃
