Meet RAG in Refact.ai: Smarter AI Coding with Repo-Level Context Awareness

May 30, 2024
by Oleg Klimov, Katia Bystrakova

Refact.ai, an AI coding assistant, launches RAG — a new feature designed to generate more relevant and customized AI suggestions by fully understanding your project’s context!

When you edit code in an IDE, the AI model typically generates suggestions based on your current file, often missing needed definitions of functions or classes from other parts of your codebase. As a result, the code written by AI can be incorrect and useless for developers.

Refact.ai addresses this problem with a solution: Retrieval Augmented Generation (RAG). It enables models to understand your entire programming environment, not just a single file, and utilize repo-level context-awareness to create coding suggestions that are significantly more relevant for both users and enterprise customers.

No doubt RAG is a must-have for advanced AI coding assistance. Let’s explore how RAG works within Refact.ai, what makes it so accurate, and how it can assist you with high-quality AI code completions and context-aware chat assistance.

What Is RAG (Retrieval Augmented Generation)?

RAG was first introduced in 2020 as a solution to the limitations of pre-trained language models. In this study, combining pre-set models and information from Wikipedia as a context source, RAG was able to generate more detailed, varied, and accurate responses.

The concept behind it is simple but effective: it connects large language models to external data, allowing LLMs to generate relevant output

RAG for code completion: Why do you need this?

To understand your current task and what code to generate for it, a RAG-powered AI model analyzes symbols around your cursor. Then, it uses the repository understanding to find related useful information, and creates code for you that is contextually correct.

For Developers: Personal codebase awareness

Imagine you have a library: HTMX

If you only have my_file.py supplied to your model, it won’t know how to complete “say_hello” or that it needs a parameter for that function.

This issue becomes worse as your project gets bigger. RAG addresses this by fetching the necessary information from your codebase to help the model be more accurate.

To summarize the impact of RAG on code completions with Refact.ai:

☹️ When the AI model only understands your current file, it might provide you with suggestions that are too generic and not contextually correct. Result: You may sometimes have useless suggestions, spending extra time fixing AI mistakes.

🤩 RAG helps the model to understand your entire programming environment, not just one file. This way, it can find the most useful data related to the coding task in different files — and generate more relevant code. Result: Completing programming tasks becomes easier and faster with accurate AI suggestions with RAG!

For Companies: Enterprise code repository awareness

Companies usually have huge codebases. Manually navigating through them to find the correct coding reference is tough and leads to long searches and mistakes. RAG makes this easy: it scans an entire company’s codebase and provides developers with accurate coding suggestions, using the code repository and project documentation as context for the answer. Whether it’s multiple, large-scale libraries or big projects with many teams, RAG finds the needed information for correct AI code completion. Context-awareness helps your programmers save time and keep the project consistent, overall making coding faster.

Make your software company benefit from RAG: get your team Refact.ai Enterprise, perfect for large codebases!

Fill the form for details, or set up an online meeting with our team.

HTMX

RAG in chat: context awareness to easier navigate the project

Refact.ai’s chat supports RAG too: you can ask questions right in your favorite IDE, using @-commands to add some important context:

@workspace, @definition, @references, @file, @symbols-at.

RAG in Refact.ai Coding Assistant: Technical Details

As you now know, in Refact.ai, RAG supports both code generation and chat LLMs, providing project-relevant code and context-aware chat assistance. To achieve this, RAG analyzes all your project data — all source files, including documentation.

Our RAG technology tracks changes as you type and packs them into the AI model context. For this, it uses a small executable file that comes with the IDE plugin, containing the AST (Abstract Syntax Tree) parser and Vector Database in-memory indexes. RAG in Refact.ai is Open-source and merely 100% Rust-based.

HTMX

Here’s how AI code generation using RAG works in the Refact.ai plugin:

  1. Refact.ai looks for identifiers around the cursor, especially type and function names;
  2. It searches for their definitions in the whole project in real time (it only takes 10ms for a repository of 10.000 files);
  3. After some clever filtering and post-processing, the AI model gets the necessary information from the other files in the project: it means it can view not only the current file, but also all the definitions and similar code examples, and use them to create code relevant completions.

This results in a measurable increase in completion quality: a random line of code has a higher probability of being exactly reproduced (from about 50% to 60% depending on the project). Accurate AI suggestions help developers finish coding tasks faster, making them more productive and happy about their work!

Oleg Klimov, CEO of Refact.ai and former OpenAI researcher, has shared insights on implementing RAG in the AI coding assistant. For a deeper understanding of the engineering decisions that shape our RAG, check out his blog post: RAG in Refact.ai: Technical Details

Try RAG using Refact.ai: Now up to 60% Probability of Accurate Code Suggestions

RAG is a must-have for developers’ productivity. It gets the context of your coding tasks and searches the entire project in real time to provide you with the right answers. With RAG in Refact.ai, programmers save time and effort: it provides relevant code suggestions exactly when needed, boosting coding efficiency and minimizing errors.

RAG is now available for Pro and Enterprise users at Refact.ai without any extra fees.

Exiting news: To celebrate the launch of RAG, we’re offering you an opportunity to try it with no limits for your coding projects:

🎉   Start your free 2-month trial of the Refact.ai Pro plan, RAG included!

Steps to Activate Your Pro Trial:

  1. Visit our Pricing page and upgrade your account to the Pro plan.
  2. Apply the REFACTRAG promo code to activate your Pro plan.
  3. Receive an email with instructions on how to enable RAG in your plugin!


If you like what we’re doing, please leave us a ⭐⭐⭐⭐⭐ on marketplaces - this will support our work.

Join our Discord to talk about RAG or give us feedback. We’ve set up a special #rag channel for your questions, and our team is there to help.

Give RAG a try to empower your programming with advanced coding suggestions. Have fun!