Get Started

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

April 17, 2024
by Oleg Klimov, Katia Bystrakova
1 min read

Refact.ai, an AI coding assistant, launches RAG! Now we offer you codebase awareness and repository-level context to deliver more customized and accurate AI suggestions, using your entire coding environment as a source of context.

When you edit code in an IDE, the code completion model typically only sees your current file. If needed definitions of functions or classes are in another file, the model won’t consider them as it can’t view the full project context. As a result, you might receive wrong and unhelpful AI suggestions.

So, how can we supply the model with the necessary information, so it can assist you better?

That’s where the Retrieval Augmented Generation (RAG) comes in. It helps the AI understand your entire programming environment, not just a single file. This way, a model can use information from different files to make coding suggestions relevant for users or enterprise customers.

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

Why Do You Need Codebase Awareness?

RAG uses the entire repository to provide AI coding suggestions, relevant to the entire codebase of software companies and individual users.

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 solves this problem by fetching the necessary information from your codebase to help the model be more accurate.

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 — 3 months free. Fill the form for details, or book a call with our team.

HTMX

How Does RAG Work in Refact.ai?

In Refact.ai, RAG supports both code generation and chat LLMs. This means RAG can assist you in finishing your code with accurate AI suggestions, as well as answering programming questions in our in-IDE chat! To achieve this, RAG analyzes all your project data — all the source files, including documentation.

Here’s how code generation works using RAG 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!

Technical Stuff About Refact.ai RAG

We use a small executable file that we ship along with the IDE plugin. It has the AST (Abstract Syntax Tree) parser and Vector Database inside, it’s self-contained, and doesn’t require you to install any additional software.

The reason why we were able to do it is Rust, an efficiently compiled language with safety guarantees.

The RAG pipeline at Refact.ai was created with some key requirements:

We will post a technical blog in the coming days that will go through all of the 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.

More relevant AI suggestions with RAG are included in Refact.ai Pro, Refact.ai Teams, and Refact.ai Enterprise plans.

How to try RAG in Refact.ai?

For the new users: install Refact.ai in your favorite code editor (VS Code, JetBrains, Visual Studio Code, or Sublime Text) and choose the Plan you want on the Pricing page.