khoj-ai / khoj

Your AI second brain. Self-hostable. Get answers from the web or your docs. Build custom agents, schedule automations, do deep research. Turn any online or local LLM into your personal, autonomous AI (e.g gpt, claude, gemini, llama, qwen, mistral).
https://khoj.dev
GNU Affero General Public License v3.0
14.1k stars 703 forks source link

[IDEA] Support file filters within a conversation #773

Closed sabaimran closed 5 months ago

sabaimran commented 5 months ago

Describe the feature you'd like

We have query filters already built in to Khoj. Oftentimes, users will want to limit their conversations to a specific file/files.

To start with, add support for limiting the query to set of files.

If a user has uploaded a file within that conversation session, automatically set that as part of the file filter.

UI Changes

Here's some inspiration for the file picker potentially. You'll want a dropdown with a list of all the files the user's uploaded to the Khoj instance. Here's a basic tutorial on dropdowns with filters:

Screenshot 2024-05-28 at 20 07 36 Screenshot 2024-05-29 at 19 39 42

You can add it in underneath the Connected notice.

Screenshot 2024-05-28 at 20 17 04

Backend Changes

In the backend, you'll want to modify this conversation object and add a field which will consist of a list of strings holding the file filters:

...
file_filters = models.JSONField(default=list)
...

To apply this change, you'll have to run python3 src/khoj/manage.py makemigrations to create the new field in the Postgres DB.

If a query lands on api_chat and its associated conversation has a query filter, you'll want to go ahead and add in those filters explicitly in the extract references method. Use the query filter documentation and the syntax in the unit tests to understand how to do this.

sabaimran commented 5 months ago

Closed with #788