{"id":23768675,"url":"https://github.com/antoinelrnld/discord-rag","last_synced_at":"2025-06-25T17:08:34.338Z","repository":{"id":270381576,"uuid":"909687862","full_name":"antoinelrnld/discord-rag","owner":"antoinelrnld","description":"Easily create a RAG based on your Discord messages","archived":false,"fork":false,"pushed_at":"2025-03-26T18:03:49.000Z","size":352,"stargazers_count":4,"open_issues_count":7,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T16:13:00.052Z","etag":null,"topics":["ai","artificial-intelligence","bot","chatgpt","chunking","discord","discord-bot","embedding","genai","generative-ai","generative-artificial-intelligence","langchain","llm","rag","retrieval-augmented-generation","vectorization"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antoinelrnld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-29T13:45:02.000Z","updated_at":"2025-03-26T18:03:38.000Z","dependencies_parsed_at":"2024-12-30T18:35:03.874Z","dependency_job_id":"0a6ce4f0-b204-40ef-b6ae-4d274e76760e","html_url":"https://github.com/antoinelrnld/discord-rag","commit_stats":null,"previous_names":["antoinelrnld/discord-rag"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/antoinelrnld/discord-rag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antoinelrnld%2Fdiscord-rag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antoinelrnld%2Fdiscord-rag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antoinelrnld%2Fdiscord-rag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antoinelrnld%2Fdiscord-rag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antoinelrnld","download_url":"https://codeload.github.com/antoinelrnld/discord-rag/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antoinelrnld%2Fdiscord-rag/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261917421,"owners_count":23229916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","artificial-intelligence","bot","chatgpt","chunking","discord","discord-bot","embedding","genai","generative-ai","generative-artificial-intelligence","langchain","llm","rag","retrieval-augmented-generation","vectorization"],"created_at":"2025-01-01T01:38:39.216Z","updated_at":"2025-06-25T17:08:34.328Z","avatar_url":"https://github.com/antoinelrnld.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Discord-RAG\n\nThis repo aims to provide a simple and fast way to create a RAG (Retrieval-Augmented Generation) application based on your Discord messages. This allows you to use an LLM that is aware of the context of your messages and can generate responses based on that. The repo also provides code to create a Discord bot that can be used to interact with the model directly in your Discord server. Ask for old informations that were discussed long ago, make summaries, ask questions about you and your friends, have fun with the bot!\n\nHere is a high-level overview of the architecture we are going to build:\n![](./docs/img/discord-rag-architecture.png)\n\nTo get started, you will need to get through the following steps:\n\n1. [Prerequisites](#1-prerequisites)\n2. [Initial Data Ingestion](#2-initial-data-ingestion)\n3. [Run the Indexing Pipeline](#3-run-the-indexing-pipeline)\n4. [Launch the API](#4-launch-the-api)\n5. [Discord Bot](#5-discord-bot)\n\n\u003e [!WARNING]  \n\u003e Keep in mind that the project is in its early stages and is only a prototype for now.\n\n## 1. Prerequisites\n\n- A [Discord Bot Token](https://discordjs.guide/preparations/setting-up-a-bot-application.html#your-bot-s-token)\n- An [OpenAI API Key](https://platform.openai.com/settings/)\n- [Docker](https://www.docker.com/) (Recommended)\n- [Docker Compose](https://docs.docker.com/compose/) (Recommended)\n\n## 2. Initial Data Ingestion\n\n![](./docs/img/initial-data-ingestion.png)\n\nFirst, you will need to export the messages from your Discord server to store them elsewhere. We are going to store them in a MongoDB database.\nYou can either use your existing MongoDB instance or get one by using the [docker-compose.yml](./docker-compose.yml) file.\n\n\u003e [!IMPORTANT]  \n\u003e Don't forget to set the required environment variables in the [.env](./initial_ingestion/src/.env) file.  \n\u003e You will need the IDs of the channels you want to export the messages from. (Comma-separated)  \n\u003e You can get it by right-clicking on the channel and selecting \"Copy ID\" in Discord (you will need to enable Developer Mode in the settings).\n\nFirst we start the MongoDB instance:\n```console\ndocker-compose up mongo -d\n```\n\nThen we start the export process:\n```console\ncd ./initial_ingestion\ndocker-compose run initial_ingestion\n```\n\n\u003e [!NOTE]  \n\u003e The extraction process can take a while depending on the number of messages in the channel(s).  \n\u003e You can keep track of the progress by checking the logs.  \n\u003e If the process is interrupted, you can restart it and it will continue from where it left off.  \n\u003e Once the process is done, you can move on to the next step.\n\n## 3. Run the Indexing Pipeline\n\n![](./docs/img/indexing-pipeline.png)\n\nNow that the messages are stored in the database, we can start the indexing pipeline. This will create the necessary indexes and embeddings for the messages to be used by the model. We are using a [SemanticChunking](https://github.com/FullStackRetrieval-com/RetrievalTutorials/blob/a4570f3c4883eb9b835b0ee18990e62298f518ef/tutorials/LevelsOfTextSplitting/5_Levels_Of_Text_Splitting.ipynb) strategy to split the messages into chunks. This allows us to group consecutive messages of the same topic together to have a better representation of the context. At least that's the idea.\n\n\u003e [!IMPORTANT]\n\u003e Don't forget to set the required environment variables in the [.env](./production/indexing_pipeline/.env) file.  \n\u003e You can let the default values if you want but you will need to set the `OPENAI_API_KEY`.\n\n```console\ncd ../ # go back to the root directory\ndocker-compose up mongo redis -d # Make sure the MongoDB and Redis instances are running\ncd ./production/indexing_pipeline\ndocker-compose run indexing_pipeline\n```\n\n\u003e [!NOTE]\n\u003e The indexing process should be relatively fast.  \n\u003e Once it's done, you can move on to the next step.\n\n## 4. Launch the API\n\n![](./docs/img/api.png)\n\nWe are now ready to launch the API that will allow us to interact with the model. The API receives a prompt from the user, retrieves the most relevant messages from the vector store, includes them in the prompt, and sends it to the model. The model then generates a response based on the context provided.  \n\n\u003e [!IMPORTANT]  \n\u003e Don't forget to set the required environment variables in the [.env](./production/api/.env) file.  \n\u003e You can let the default values if you want but you will need to set the `OPENAI_API_KEY`.\n\n```console\ncd ../.. # go back to the root directory\ndocker-compose up api -d\n```\n\n### Using the API\n\nThe API provides two endpoints:\n\n| Method | Endpoint | Description | Parameters |\n|--------|----------|-------------|------------|\n| GET | /health | Check if the API is running | |\n| POST | /infer | Generate a response based on the prompt | `text` (Multipart-FormData) |\n\n\n- `/infer` will return a JSON response with the generated text.\n    ```json\n    {\n        \"question\": \"Tell me what you know about the time we went to the beach last summer.\",\n        \"context\": [\"...\", \"...\"],\n        \"answer\": \"When you went to the beach last summer, it was a sunny day and you had a lot of fun. You played volleyball and swam in the sea. You also had a picnic and watched the sunset. It was a great day!\"\n    }\n    ```\n- `/health` will return a JSON response with the status of the API.\n    ```json\n    {\n        \"status\": \"ok\"\n    }\n    ```\n\n\u003e [!TIP]  \nAt this point the RAG application is ready to be used. Feel free to integrate it in any application. If you want to interact with the model directly in your Discord server, we provide the code of a Discord bot that you can use in the next section.\n\n## 5. Discord Bot\n\n\u003e [!CAUTION]  \n\u003e The real-time data ingestion is not implemented yet.\n\n![](./docs/img/bot.png)\n\nThe Discord bot allows you to chat with the model directly in your Discord server. This way, everyone in your server can easily use the RAG application seamlessly. To interact with the bot, use the `/ask` command followed by the question you want to ask. The bot will then generate a response based on the context of the messages it has seen.\n\n\u003e [!IMPORTANT]  \n\u003e Don't forget to set the required environment variables in the [.env](./bot/src/.env) file.  \n\u003e You will need the `DISCORD_BOT_TOKEN` and the `DISCORD_BOT_CLIENT_ID`.  \n\u003e You can find the CLIENT_ID of your bot in the [Discord Developer Portal](https://discord.com/developers/applications) (Named \"Application ID\").\n\n```console\ndocker-compose up bot -d\n```\n\n## Et Voilà!\n\n![](./docs/img/discord-rag-architecture.png)\n\nWe built a simple RAG application for Discord! Feel free to contribute to the repo and suggest improvements. For now it is still a proof of concept, there is a lot of room for improvement.  \n\nOnce you went through all the steps at least once, you can start the whole application with a single command:\n\n```console\n$ docker-compose up -d\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantoinelrnld%2Fdiscord-rag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantoinelrnld%2Fdiscord-rag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantoinelrnld%2Fdiscord-rag/lists"}