253 points · by dakshgupta · 2y ago · 166 comments
We are far from the first people to try "RAG on your codebase". We focus on full codebase comprehension: using LLMs to accurately answer difficult questions with full context of large, complex, and even multi-repo codebases.
Simple RAG alone is not sufficient for this task. Codebases aren’t like most PDFs, docs, or other similar data types. They are graphs—complex puzzles where each piece is interlinked. So Greptile does a few things past simple RAG:
(1) Instead of directly embedding code, we parse the AST of the codebase, recursively generate docstrings for each node in the tree, and then embed the docstrings.
(2) Alongside vector similarity search and keyword search, we do “agentic search” where an agent reviews the relevance of the search results, and scans the source code to follow references that might lead to something important. Then it returns the relevant sources.
For example, here are a couple questions that this system is able to answer in our test repo that simple RAG couldn’t (in our experience):
“Where are the auth providers configured?” (They are in an array inside of an options.ts file, where looking at the file it’s not obvious it’s an auth related file. However, because that array is imported into the auth/route.ts file, Greptile’s agent traces and find it)
“How would I add a postgres connector?” (The best way to answer this is to see how the Redis connector is set up and mirror it. Simple RAG sometimes retrieves some of the code for the Redis connector, but Greptile’s agent follows the connections to retrieve all the code that the redis connector touches, and uses that to write instructions.)
Developers (including at Stripe and Microsoft) are using Greptile for things like:
Debugging—you can paste in an error message and it does a pretty good job of diagnosing the root cause and suggesting fixes.
Grokking OSS repos—for example, if you're forking a repo, modifying it for your usecase, or just integrating it, Greptile lets you add multiple repos and dependencies in the same chat session so it has full context.
Parsing legacy code at work—especially if original engineers have left the company.
Since we're accessing your private code, we're very careful with security. We don't store any code on our servers after initial processing, and just pull snippets as needed from the GitHub API.
Quick note: when you sign in with GH, it might ask for permission to "act on your behalf". This is a quirk of GitHub's wording—our permissions are read-only and the only thing we do "on your behalf" is read code, so we can index the repo.
We came up with this idea while working at AWS—the codebase was super complicated, the docs were sparse and out of date, and our team was remote so it was slow to get answers to questions. We picked "greptile" because of "grep" and also we just wanted a somewhat silly name.
Try it out! It's a work in progress, so any feedback is appreciated. Here are the links again: for popular open source repos see https://app.greptile.com/repo, and to get it working on your own repo, start at https://app.greptile.com.
If you have experience working with a complex codebase at work or for a project, I’d love to hear about it. It really helps us educate our product direction. Looking forward to comments!
edit. For those who want to try this on large or private repos, here is a promo code for a free month: HACKERNEWS100
"When using "as_json" in a controller to return the JSON of a model, how are BigDecimal's encoded?"
Answer: "When using as_json in a controller to return the JSON of a model, BigDecimal values are encoded as strings. This behavior is defined in the active_support/core_ext/object/json.rb file, specifically in the BigDecimal class extension for JSON encoding. The rationale behind this approach is that most..." which is exactly the case as I learnt through various PR's, Issues and code review.
This would have saved me about 30mins of work. I wonder if it takes into account the metadata, such as authors, related comments, issues and PRs?
At one point, this random prompt popped up: https://imgur.com/a/mYeluaU —what's "Onboard?" Is this some kind of weird LLM leakage/hallucination?
With all respect, this is like a pre-MVP quality product. The codebase isn't even particularly large and the experience is extremely sub-par. Charging for something like this is honestly highway robbery.
- processing is usually stuck at 99% because when we order the components of the repository by file-directory dependency and ast dependency, there are a lot, LOT more leaves than the internal nodes + the root. Since we have to have the results of the dependency before we move on, moving up the dependency chain with llm calls take a while. This is even more pronounced when nearing the root for completion. We are working on optimizing this flow as it is very annoying for us as well.
- "Error: Internal error while locating sources": this is embarrassing but we did experience a database outage today (I wonder why) some repositories have a faulty status. It should be back up now and we are working to recover/reprocess the repos that have failed during the outage (including dvx/lofi)
- "Onboard" that was our previous name, this has slipped through the cracks, thanks for pointing it out!
We are trying to parse most of the popular open source repos (we have processed repos like python, vscode, etc). We are hoping to fully process the linux kernel soon as well (a personal benchmark of mine).
Why call it 99% then, call it 49%.
Presumably it’s great news that I can RAG on my codebase. But I’m not sure whether I’ve ever ragged anything in my career or whether I’ll want to now.
If you told us what it meant, we could probably understand what your thing does.
RAG -> retrieval augmented generation. Given a query, finding the parts of the codebase most relevant to the query, and supplying it to the LLM so it can answer the query. The typical way to do this is semantic similarity, or chunking + embedding the corpus being searched, embedding the query and finding the k most cosine-similar chunks.
You’ll want to find a balance between telling people what your thing does with no jargon or acronyms whatsoever, while signaling to people who know as much as you about this stuff (all four of them) that it’s got those cool ingredients.
All the best.
This looks great - I just tried to generate sample code in the react repo and was pleasantly surprised. Do you have a sense of whether this works well to generate code in general, i.e. generate an API route to return X data that works similar to the other API routes.
We haven't built it for code gen in particular, but a lot of our users seem to be using it for that. We want to really nail down people getting to understand what is going on in the codebase itself.
Are you storing the embedding vectors you've calculated from the code? If so, those are likely quite easily reversible - so I would still consider that source code stored on your servers from the point of view of a security audit.
As a result, I might actually prefer to have copies of my code stored on your servers if it resulted in faster performance.
I don't think embeddings are generally reversible... you're usually projecting onto a lower dimensional space, and therefore losing information.
> We train our model to decode text embeddings from two state-of-the-art embedding models, and also show that our model can recover important personal information (full names) from a dataset of clinical notes.
https://arxiv.org/pdf/2310.06816.pdf
There's certainly information loss, but there is also a lot of information still present.
“a multi-step method that iteratively corrects and re-embeds text is able to recover 92% of 32-token text inputs exactly”.
In theory if you know the model being used you could reverse them.
This is important because I'm not deeply familiar with public projects, so I can't accurately assess if the tool is worthwhile. Whereas with one of my repos, I'd be able to tell quality pretty quickly.
HACKERNEWS100
The latter is typically the realm of requirements, design documentation, and possibly test plans.
Generating such documentation from code seems quite impossible, or at least wrong.
It is unfortunate that most open source software is lacking in such documentation, giving off bad signals to junior developers.
Edit: not to take away from the product being discussed here, which seems very useful! I am merely supporting the parent here.
You forgot one of the biggest spots for "why" documentation... git commit messages, where the point is to say why you made this change. Maybe taking into account the commit messages around the code in question would help.
Still a great idea, though. Ingesting all data from JIRA may be beneficial as well.
https://app.greptile.com/share/4953cbff-13ec-4427-b0af-02889...
Thanks for pointing that out!
1. "We will email you"... "once the repositories have finished processing" Not sure you're supposed to do that without consent, when the intent was just to connect GitHub! Email use is supposed to be opt-in.
2. My tiny repo (https://github.com/lukestanley/ChillTranslator) won't load.
3. The UI for selecting a GitHub repo is hard to find and fiddly to use.
4. I couldn't see where to put the promo code.
2. Sadly, AWS just went down, absolute scramble at the office
3. Fiddly is the right word, we just changed it a couple days ago. Will make it cleaner.
4. You should only need that if you’re planning to upgrade, so you can click on the upgrade button and you should see a “Add promotion code” option on the left of checkout.
Cursor is different because it's really focused on augmenting the code writing experience with code gen, while we're working on code comprehension.
A good way to look at it is - Cursor replaces your IDE, Greptile replaces/augments your internal docs.
My first thought for RAG is "Red, Amber, Green" as used on risks etc. with project management.
Does it integrate with Visual Studio, does it provide code suggestions?
Been doing a lot of back and forth iteration with ChatGPT to build a python project from scratch
It’s been a really good experience although frustratingly slow at times (from going back and forth between the browser and code and having to wait for gpt’s answers)
Can more documentation be automatically added? For example, it might be useful in a rails project to be able to get answers about the ruby and rails documentations
Docs is a good idea but we haven't found a reliable enough scraper to add docs from a website. We were thinking it would be cool if you could drop in like "docs.stripe.com" and it automatically adds stripe docs to the context.
"Link Your Code Hosting Providers Connect your accounts for seamless integration, and to access private repositories."
What does this mean?
1. Haven’t figured out what should trigger updates. Every commit sounds crazy, every save would be perfect but too intensive also.
2. LLMs will not be self hosted. We haven’t been able to get the same results with any smaller LLMs
To answer your questions we definitely want to make this available for local repos and ideally self hosted, on a technical level that’s probably several month away.
You can also email me at daksh [at] greptile.com and I’ll set a reminder to let you know when it’s out
What triggers updates when it is not local?
I've given it a fairly serious shot and my conclusion is that building IDE hooks is seriously depressing. IntelliJ deprecates APIs constantly and the docs don't really keep up.
And then there's the total dumpster fire that is trying to support GPU acceleration on multiple platforms.
Unfortunately it's easily 10x the work to do this kind of thing local only.
Edit: Some of the repos that were processing at the time might have failed to process. Reach out to us on Discord if you're seeing errors.
It's a terrible choice of acronym if you ask me.
I had scrolled past this article without clicking and had the same thoughts about how I'd approach this.
> Oops
> We couldn't access this repo.
> You may need to log in to view this repository, or it might not exist.
It also appears that the vote buttons do nothing if one is not logged in, so I'd recommend eliding them unless logged in since it's just frustrating to wonder if some JS error ate the vote or what
Also I am getting the 'Error: Internal error while processing request'
I can only think of two serious competitors, neither of which is open source. And I don't think anyone serious at either of those companies would claim that they have the definitive solution.
nice
Excited to try it out
I'd like to see if your tech solves those issues.