Show HN: Khoj – Chat offline with your second brain using Llama 2 (github.com)
Once we made Khoj search incremental, I completely stopped using the default incremental search (C-s) in Emacs. Since then Khoj has grown to support more content types, deeper integrations and chat (using ChatGPT). With Llama 2 released last week, chat models are finally good and easy enough to use on consumer hardware for the chat with docs scenario.
Khoj is a desktop application to search and chat with your personal notes, documents and images. It is accessible from within Emacs, Obsidian or your Web browser. It works with org-mode, markdown, pdf, jpeg files and notion, github repositories. It is open-source and can work without internet access (e.g on a plane).
Our chat feature allows you to extract answers and create content from your existing knowledge base. Example: "What was that book Trillian mentioned at Zaphod's birthday last week". We personally use the chat feature regularly to find links, names and addresses (especially on mobile) and collate content across multiple, messy notes. It works online or offline: you can chat without internet using Llama 2 or with internet using GPT3.5+ depending on your requirements.
Our search feature lets you quickly find relevant notes, documents or images using natural language. It does not use the internet. Example: Search for "bought flowers at grocery store" will find notes about "roses at wholefoods".
Quickstart:
pip install khoj-assistant && khoj
See https://docs.khoj.dev/#/setup for detailed instructionsWe also have desktop apps (in beta) at https://github.com/khoj-ai/khoj/releases/tag/0.10.0 if you want to try them out.
Please do try out Khoj and let us know if it works for your use cases? Looking forward to the feedback!
153 comments
[ 2786 ms ] story [ 1388 ms ] threadPlease, someone make a home-assistant Alexa clone for this.
We've just been testing integrating over voice, whatsapp over the last few days[1][2] :)
[1]: https://github.com/khoj-ai/khoj/tree/khoj-chat-over-whatsapp...
[2]: https://github.com/khoj-ai/khoj/compare/master...features/wh...
Would be hella nice to connect all the scattered lines of thoughts in various notes on a variety of platforms.
Would some summary of previous day would be helpful to you? Is your memory problem only episodic, or does it extend to factual and kinesthetic as well?
Basically like a gopro on steroids with searchable context - or even the ability for me to say outloud "KEEP A NOTE OF THIS" and it will keep a segment tagged and can give me summaries of moments I wanted particularly logged...
I applied to YC with an idea 'sorta' like this almost a decade ago.
The idea was to have a timeline of communications between all my contacts such that I could side-scroll a timeline with dots of actions such a "sent email" "made call" "sent text" received txt" and I could see all these in filters by contacts/day whatever...
This was pre-snowden, so I didnt have confirmation that there were already people doing this for me, just not letting me browse my own data ;-)
Can I get that via GDPR? Has anyone tried?
For Android users a more straightforward option is location history, but you should probably turn that off.
For example, if I stayed at an Airbnb last year in Houston and needed to lookup the address for some reason, I'd be going either to gmail and running some keywords searches ("Houston", "Airbnb"), or going to my Airbnb app.
Really, I want a single endpoint where all my personal data can be made available to me, ideally without sacrificing my privacy. Location's a cool use case.
This is generally called Lifelogging. https://roberdam.com/en/wisper.html - roberdam@ created basically what you just said, but focused on Audio, not Video.
https://news.ycombinator.com/item?id=29692087 has some possible info too.
If you can collate your notes into markdown or some such, then messy notes can be handled, at least using Khoj with GPT3.5+.
Do let us know how we can help out and what your current biggest pain-points are?
It screencaps your desktop every 5 sec so you can watch a timelapse of how you spent your day. (Assuming it was on the computer!)
I did find it heavy on the disk usage so I wrote a ffmpeg script to convert it to video (much more efficient).
I've tried dozens of notetaking apps and that's the only one that truly felt like a second brain.
It's because of the speed. Infuriatingly, Obsidian for example can search just as fast, but they intentionally programmed in a lag after each keystroke... (I know because I removed it.)
Yeah, it's seems they've added a debounce. I'd prefer to set it to 0ms as well. Do you remember how you removed it?
https://github.com/jonmest/How-To-Tamper-With-Any-Electron-A...
Obsidian is not open source so it's minified and hard to read. But I was able to find the relevant code and just set the delay to 0.
(I'm away from computer now, I'll see if I can find the code later.)
What also helped is that all Electron apps are just Chromium so you can run the dev tools and the debugger! I think the hotkey is F12, and/or Ctrl+Shift+J.
Alternatively, you could get near-zero delay and no spurious queries by requiring the user type Enter or click a button... but that design is much less common these days.
However, updating Obsidian actually made it slower for me, because 1.4.2 is only available to paid users. So it updated to 1.3.7 and removed my patch!
A number of apps that are designed for OpenAI’s completion/chat APIs can simply point to the endpoints served by llama-cpp-python [0], and function in (largely) the same way, while using the various models and quants supported by llama.cpp. That would allow folks to run larger models on the hardware of their choice (including Apple Silicon with Metal acceleration or NVIDIA GPUs) or using other proxies like openrouter.io. I enjoy openrouter.io myself because it supports Anthropic’s 100k models.
[0]: https://github.com/abetlen/llama-cpp-python
I'll provide my insight from experimentation integrating Llama V2/GPT4All into Khoj -- Falcon 7b is probably the runner up in models that can be supported on consumer hardware, and it really wasn't good enough (for me) on my machine to be useful. The token consumption with personal notes context is too large, and the content too variable for a small model like that to be able to understand it. It's fine if you're just doing normal question-answering back and forth, but you don't need Khoj for that.
My workflow looks like: 1. Search with Khoj search[1]: `C-c s s` <search-query> RET 2. Use speed key to jump to relevant entry[2]: with `n n o 2`
[1]: `C-c s` is bound to `khoj` transient menu [2] https://orgmode.org/manual/Speed-Keys.html
Khoj works more like an incremental, natural language version of org-agenda-search (or projectile) rather than isearch.
You've to configure which files it should index first. You can then use natural language to search those files with a search-as-you-type experience.
This is not the same as isearch that just searches the current file for keyword matches.
Second, khoj doesn't index source code and the default search models don't work well with code files.
But yeah someone should implement a natural language isearch as a standalone tool (as suggested by parent comment). It'd be super-useful
Is there a way to have this bot read from a discord and google drive?
[1] https://gpt4all.io/index.html
[1]: https://github.com/khoj-ai/khoj/issues/141
----
What model size/particular fine-tuning are you using, and how have you observed it to perform for the usecase? I've only started playing with Llama 2 at 7B and 13B sizes, and I feel they're awfully RAM heavy for consumer machines, though I'm really excited by this possibility.
How is the search implemented? Is it just an embedding and vector DB, plus some additional metadata filtering (the date commands)?
Khoj is using the Llama 7B, 4bit quantized, GGML by TheBloke.
It's actually the first offline chat model that gives coherent answers to user queries given notes as context.
And it's interestingly more conversational than GPT3.5+, which is much more formal
How are you determining what notes (or snippets of notes?) to be injected as context? Especially given the small 2048 context limit with Llama 1.
We determine note relevance by using cosine similarity between the query and the knowledge base (your note embeddings). We limit the context window for Llama2 to 3 notes (while OpenAI might comfortably take up to 9). The notes are ranked based on most to least similar and truncated based on the context window limit. For the model we're using, we're still limited to 2048 tokens for Llama v2.
https://together.ai/blog/llama-2-7b-32k
Llama 2 gives great answers, even the 7B model. There’s an “uncensored” 7B version as well George Sung has fine-tuned for topics that the default Llama2 model won’t discuss - eg I had trouble having Llama2 review authentication/security code or topics: https://huggingface.co/TheBloke/llama2_7b_chat_uncensored-GG...
From just playing around with it the uncensored model still seems to know where to “draw the line” on sensitive topics but YMMV
If you do end up checking out Ollama you can try it with with this command or there’s an API too (it’s not in the docs yet)
Yeah, I ran into a couple of funny edge cases using Llama v2 with my personal notes. For example, if I ever asked it anything remotely personal (as I would with a personal assistant), it would often start telling me that asking for personal data is unethical. I get it, you have to be careful with the open source LLMs, but still a bit funny. It does work with enough coaxing though.
The 7B version was a decent enough starting point in terms of what it can answer (and way fewer folks can run a 13B on their machine).
If you really want you can just replace the 7B model file with the 13B one under the ~/.cache/gpt4all directory on your device and it should just work.
I am sufficiently uneducated on the ins and outs of AI integrations to always wonder if projects like this one can be used in local-only mode, i.e. when self-hosted ensuring me that never any of my personal information is sent to a remote service. So it would be very helpful to very explicitly give me that assurance of privacy, if that's the case.
It would be awesome if it could also index a directory of PDFs, and if it could do OCR on those PDFs to support indexing scanned documents. Probably outside of the scope of the project for now, but just the other day I was just thinking how nice it would be to have a tool like this.
etc...
I've wanted a "COMPUTER.", uh... I say "COMPUTER!", 'sir, you have to use the keyboard', ah a Keyboard, how quaint.... forever.
Of course, having it be stable enough to not `rm -rf /` soon after is definitely not part of the warranty
-
So aside from doing something such as this - whats the size of your current usecase - is it being able to search and org a large orge of devs through files and directories/repos/whatever?
What if you had a global glob of data/code/files - and as an enterprise you can just give each new emp an employee role, and based on their job and purported skills, just throw them at the monolith, yet the AI will tailor the info they get out of the glob.
"User10267A - you are chartered with working on projects XYZ, based on your skillset - here are a few assessments to see which sections of the codebase best suit you."
[does work]
"OK .U267A, here is your workspace with all auths to the libs and such youll need to work on [PROJECT FSPEZ]"
Khoj can index directory of PDFs for search and chat. But it does not currently work with scanned PDF files (i.e not with ones without selectable text).
Being able to work with those would be awesome. We just need to get to it. Hopefully soon
Or at least models that don’t hog so much RAM.
The RAM usage is kind of the point though; we're trading space for time. It's not a problem that the model is using it, it's just that with the default choice for UI being web based now, the unnecessary memory usage of browsers is actually starting to be a real pain point.
2. The web UI isn't required if you use Obsidian or Emacs. That's just a convenient, generic interface that everyone can use.
For now, local LLMs take up an egregious about of RAM, totally agreed. But we trust the ecosystem is going to keep improving and growing and we'll be able to make improvements over time. They'll probably become efficient enough where we can run them on phones, which will unlock some cool scope for Khoj to integrate with on device, offline assistance.
Irrelevant opinion - The logo is beautiful, I like it and so are the colours used.
Lastly, LLMA2 for such use cases, I think is capable enough that paying for ChatGPT won't be as lucrative especially when privacy is of concern.
Keep it up. Good craftsmanship. :)
Ideal: 16Gb (GPU) RAM
Less Ideal: 8GB RAM and CPU
What about if I have a GPU with 8GB?
Khoj and your other apps need more RAM themselves, so practically 8GB of System or GPU RAM should suffice.
Khoj has been tested with CUDA and Metal capable GPUs. So Nvidia and Mac M1+ GPUs should work. I'm think it'll work with AMD GPUs out of the box too but let me know if it doesn't for you? I can look into what needs to be done to get that to work.
[1]: The calculation is [params] * [bytes] GB RAM, so 7 * 0.5 = 3.5Gb
PS. Nice to see an Hindi name for a software. For those who don't speak Hindi: https://en.m.wiktionary.org/wiki/%E0%A4%96%E0%A5%8B%E0%A4%9C...
But that would allow you to access Khoj from the web.
This is getting very close to my ideal of a personal AI. It's only gonna be a few more years until I can have a digital brain filled with everything I know. I can't wait
Does anyone have recommendations for a tool that does it?
Or, anyone want to build it together?
Having something that indexes all your digital travels and makes it easily digestible will be gold. Hopefully Khoj can become that :)
There was.
It was called Google Desktop Search, it was awesome, and it was axed.
That said, today I wouldn't use it anyway as both I and Google have changed a lot.
You've come a good way in both directions: the messaging is clearer about current state vs aspirations, and you've made good progress towards the aspirational parts.
Really glad to see the warm reception you're getting now. Nice job, y'all.
Could you elaborate on the incremental search feature? How did you implement it? Don't you need to re-encode the full query through a SBERT or such as each token is written (perhaps with debouncing)?
Also, having an easily-extended data connector interface would be awesome, to connect to custom data sources.
Yes, we don't do optimizations on the query encoding yet. So SBERT just re-encodes the whole query every time. It gets results in <100ms which is good enough for incremental search.
I did create a plugin system, so that a data plugin just has to convert the source data into a standardized intermeditate jsonl format. But this hasn't been documented or extensively tested yet.
I got really excited about this and fired it up on my petite little M2 Macbook Air only for it to grind it to a halt. Think the old days when you had a virus on your PC and you'd move the mouse then wait 45 seconds to see the cursor move. It honestly made me feel nostalgic. I guess I have to taper performance expectations with this Air, though this is the first time it's happened.
lscpu output: Architecture: x86_64
CPU(s): 8 Vendor ID: GenuineIntel xsaveopt dtherm ida arat pln pts md_clear flush_l1d NUMA:We also have some fixes and perf improvements we plan to release later today in version 0.10.1
We use it for understanding usage -- like determining whether people are using markdown or org or more.
Everything is collected entirely anonymized, and no identifiable information is ever sent to the telemetry server.
To opt-out, you set the `should-log-telemetry` value in `khoj.yml` to false. Updated the docs to include these instructions and what we collect -- https://docs.khoj.dev/#/telemetry.
1. If you want better adoption especially among corporations, GPL-3 wont cut it. Maybe think of some business friendly licenses (MIT etc)
2. I understand the excitement about llm's. But how about making something more accessible to people with regular machines and not state of art. I use rip-grep-all (rga) along with fzf [1] that can search all files including pdfs in a specific folders. However, I would like a GUI tool to
This is sufficient for 95% of my usecases to search locally and I don't need LLM. If khoj can enable such search as default without LLM that will be a gamechanger for many people without a heavy compute machine or who dont want to use OpenAI.[1] https://github.com/phiresky/ripgrep-all/wiki/fzf-Integration
Have a look at how that worked out for the folks who built node and its libraries versus the ones who maintained control of their work (like npm).