Commit Graph

5013 Commits

Author SHA1 Message Date
Debanjum
40488b3b68 Remove redundant exception for retry calls to gemini api
httpx ReadError inherits from NetworkError so not required to mention
it explicitly in gemini api call retry check
2025-08-23 00:48:10 -07:00
Debanjum
8aa9c0f534 Reduce max reasoning tokens for gemini models
A high reasoning tokens does not seem to help for standard Khoj use
cases. And hopefully reducing it may avoid repetition loops by model.
2025-08-23 00:48:10 -07:00
Debanjum
2823c84bb4 Default to gemini 2.5 model series on init and for eval 2025-08-22 20:34:38 -07:00
Debanjum
c53a70c997 Share debug logs from github eval run for debugging 2025-08-22 19:06:37 -07:00
Debanjum
e2f377c27b Render file reference as link with file preview on hover/click in web app
Overview
- Khoj references files it used in its response as markdown links.
  For example [1](file://path/to/file.txt#line=121)
- Previously these file links were just shown as raw text
- This change renders khoj's inline file references as a proper links
  and shows file content preview (around specified line if deeplink)
  on hover or click in the web app

Details
- Render inline file references as links in chat message on web app.
  Previously references like [1](file://path/to/file.txt#line=120)
  would be shown as plain text. Now they are rendered as links
- Preview file content of referenced files on click or hover.
  If reference uses a deeplink with line number, the file content
  around that line is shown on hover, click. Click allows viewing file
  preview on mobile, unlike hover. Hover is easier with mouse.
2025-08-22 18:24:27 -07:00
Debanjum
d8b7e9c8a5 Handle unset content type key when indexing knowledge base on server 2025-08-22 18:24:27 -07:00
Debanjum
3c3205bb06 Fix and improve file read, write handling in Obsidian
Fixes
- Fix to allow khoj to delete content in obsidian write mode
- Do not throw error when no edit blocks in write mode on obsidian
- Limit retries to fix invalid edit blocks in obsidian write mode

Improvements
- Only show 3 recent files as context in obsidian file read, write mode
- Persist open file access mode setting across restarts in obsidian
- Make khoj obsidian keyboard shortcuts toggle voice chat, chat history
- Do not show <SYSTEM> instructions in chat session title on obsidian

Closes #1209
2025-08-20 20:20:12 -07:00
Debanjum
48ed7afab8 Do not show <SYSTEM> instructions in chat session title on obsidian
In obsidian we have a hacky system instruction being passed in read,
write file access modes. This shouldn't be shown in chat sessions list
during view or edit. It is an internal implementation detail.
2025-08-20 20:18:27 -07:00
Debanjum
82dc7b115b Fix to allow khoj to delete content in obsidian write mode
Previous regex and replacement logic did not allow replace block to be
empty
2025-08-20 20:18:27 -07:00
Debanjum
7645cbea3b Do not throw error when no edit blocks in write mode on obsidian
Editing is an option, not a requirement in file write/edit mode.
2025-08-20 20:18:27 -07:00
Debanjum
2e6928c582 Limit retries to fix invalid edit blocks in obsidian write mode 2025-08-20 20:18:27 -07:00
Debanjum
c5e2373d73 Make khoj obsidian keyboard shortcuts toggle voice chat, chat history
Previously hitting voice chat keybinding would just start voice chat,
not end it and just open chat history and not close it.

This is unintuitive and different from the equivalent button click
behaviors.

Fix toggles voice chat on/off and shows/hides chat history when hit
Ctrl+Alt+V, Ctrl+Alt+O keybindings in khoj obsidian chat view
2025-08-20 20:18:27 -07:00
Debanjum
d8b2df4107 Only show 3 recent files as context in obsidian file read, write mode
Related #1209
2025-08-20 20:18:27 -07:00
Debanjum
eb2f0ec6bc Persist open file access mode setting across restarts in obsidian
Allows a lightweight mechanism to persist this user preference.
Improve hover text a bit for readability.

Resolves #1209
2025-08-20 20:18:27 -07:00
Debanjum
2884853c98 Make plugin object accessible to chat, find similar panes in obsidian
Allows ability to access, save settings in a cleaner way
2025-08-20 20:18:27 -07:00
Debanjum
9f6aa922a2 Improve Khoj research tools, gpt-oss support and ai api usage
Better support for GPT OSS
- Tune reasoning effort, temp, top_p for gpt-oss models
- Extract thoughts of openai style models like gpt-oss from api response

Tool use improvements
- Improve view file, code tool prompts. Format other research tool prompts
- Truncate long words in code tool stdout, stderr for context efficiency
- Use instruction instead of query as code tool argument
- Simplify view file tool. Limit viewing upto 50 lines at a time
- Make regex search tool results look more like grep results
- Update khoj personality prompts with better style, capability guide

Web UX improvements
- Wrap long words in train of thought shown on web app
- Do not overwrite charts created in previous code tool use during research
- Update web UX when server side error or hit stop + no task running

Fix AI API Usage
- Use subscriber type specific context window to generate response
- Fix max thinking budget for gemini models to generate final response
- Fix passing temp kwarg to non-streaming openai completion endpoint
- Handle unset reasoning, response chunk from openai api while streaming
- Fix using non-reasoning openai model via responses API
- Fix to calculate usage from openai api streaming completion
2025-08-20 20:06:18 -07:00
Debanjum
13d26ae8b8 Wrap long words in train of thought shown on web app 2025-08-20 19:07:28 -07:00
Debanjum
fb0347a388 Truncate long words in stdout, stderr for context efficiency
Avoid long base64 images etc. in stdout, stderr to result in context
limits being hit.
2025-08-20 19:07:28 -07:00
Debanjum
dbc3330610 Tune reasoning effort, temp, top_p for gpt-oss models 2025-08-20 19:07:28 -07:00
Debanjum
83d725d2d8 Extract thoughts of openai style models like gpt-oss from api response
They use delta.reasoning instead of delta.reasoning_content to share
model reasoning
2025-08-20 19:07:28 -07:00
Debanjum
f483a626b8 Simplify view file tool. Limit viewing upto 50 lines at a time
We were previously truncating by characters. Limiting by max lines
allows model to control line ranges they request
2025-08-20 19:07:28 -07:00
Debanjum
f5a4d106d1 Use instruction instead of query as code tool argument 2025-08-20 19:07:28 -07:00
Debanjum
c5a9c81479 Update khoj personality prompts with better style, capability guide
- Add more color to personality and communication style
- Split prompt into capabilities and style sections
- Remove directives in personality meant for older, less smart models.
- Discourage model from unnecessarily sharing code snippets in final
  response unless explicitly requested.
2025-08-20 19:07:28 -07:00
Debanjum
2c91edbb25 Improve view file, code tool prompts. Format other research tool prompts 2025-08-20 19:07:28 -07:00
Debanjum
452c794e93 Make regex search tool results look more like grep results 2025-08-20 19:07:28 -07:00
Debanjum
9a8c707f84 Do not overwrite charts created in previous code tool use during research 2025-08-20 19:07:28 -07:00
Debanjum
e0007a31bb Update web UX when server side error or hit stop + no task running
- Ack websocket interrupt even when no task running
  Otherwise chat UX isn't updated to indicate query has stopped
  processing for this edge case

- Mark chat request as not being procesed on server side error
2025-08-20 19:07:28 -07:00
Debanjum
222cc19b7f Use subscriber type specific context window to generate response 2025-08-20 19:07:28 -07:00
Debanjum
ff73d30106 Fix max thinking budget for gemini models to generate final response 2025-08-20 19:07:28 -07:00
Debanjum
34dca8e114 Fix passing temp kwarg to non-streaming openai completion endpoint
It is already being passed in model_kwargs, so not required to be
passed explicitly as well.

This code path isn't being used currently, but better to fix for
if/when it is used
2025-08-20 19:07:28 -07:00
Debanjum
8862394c15 Handle unset reasoning, response chunk from openai api while streaming 2025-08-20 19:07:28 -07:00
Debanjum
14b4d4b663 Fix using non-reasoning openai model via responses API
Pass arg to include encrypted reasoning only for reasoning openai
models. Non reasoning openai models do not except this arg
2025-08-20 19:07:28 -07:00
Debanjum
e504141c07 Fix to calculate usage from openai api streaming completion
During streaming chunk.chunk contains usage data. This regression must
have appeared while tuning openai stream processors
2025-08-20 19:07:28 -07:00
Debanjum
573c6a32e1 Fix to create chat with custom agents from obsidian (#1216)
The function createNewConversation is never called with the agentSlug
specified so its always opening a new Conversation with the default Agent
2025-08-20 19:07:16 -07:00
Debanjum
4728098cad Fix to set agent for new chat created from obsidian
- Set the agent of the current conversation in the agent dropdown when a new conversation with a non-default agent is initialized. This was unset previously.
- Pass the current selected agent in the dropdown when creating new chat
- Correctly select the `khoj-header-agent-select' element
2025-08-21 07:33:25 +05:30
Fh26697
a2a3eb8be6 Update chat_view.ts
fixed Typo
2025-08-20 17:01:47 +02:00
Fh26697
b3015f6837 Update chat_view.ts
fixed Typo
2025-08-20 16:58:08 +02:00
Fh26697
916534226a Chats are not using specified Agent
The function createNewConversation is never called with the agentSlug specified so its always opening a new Conversation with the Base Agent
2025-08-19 15:49:41 +02:00
Debanjum
fa143d45b9 Fix passing images to official openai models using the responses api 2025-08-17 16:30:43 -07:00
Debanjum
a494a766a4 Fix eval github workflow and show more logs to debug its startup 2025-08-15 16:26:37 -07:00
Debanjum
25e549d683 Show connection lost toast if disconnect while processing chat request 2025-08-15 16:04:26 -07:00
Debanjum
59bfaf9698 Fix to indicate ws disconnect on web app & save interrupted research
- A regression had stopped indicating to user that the websocket
connection had broken. Now the interrupt has some visual indication.

- Websocket disconnects from client didn't trigger the partial
research to be saved. Now we use an interrupt signal to save partial
research before closing task.
2025-08-15 16:04:26 -07:00
Debanjum
3eb8cce984 Retry if hit gemini rate limit. Return friendly message if retries fail
Although we had handling in place for retrying after gemini suggested
backoff on hitting rate limits. The actual rate limit exception was
getting caught to render friendly message, so retry wasn't actually
getting triggered.

This change allows both
- Retry on hitting 429 rate limit exceptions
- Return friendly message if rate limit triggered retry eventually fails

Related:
- Changes to retry with gemini suggested backoff time in 0f953f9
2025-08-15 16:04:25 -07:00
Debanjum
4274f58dbd Show more specific warning to llm on duplicate tool use during research 2025-08-15 16:02:32 -07:00
Debanjum
caf0b994e8 Fix handling failure to select default chat tools
Issue: chosen_io variable was accessed before initialization when
ValueError was raise.

Fix: Set chosen_io to fallback values on failure to select default
chat tools
2025-08-15 16:02:15 -07:00
Debanjum
7251b25c66 Handle null reference exceptions when rendering files context 2025-08-15 16:00:51 -07:00
Debanjum
20347e21c2 Reduce noisy indexing logs 2025-08-12 12:06:43 -07:00
Debanjum
bd82626084 Release Khoj version 2.0.0-beta.13 2025-08-11 22:29:06 -07:00
Debanjum
cbeefb7f94 Update researcher prompt to handle ambiguous queries. Clear stale text
Make researcher handle ambiguous requests better by working with
reasonable assumptions (clearly told to user in response) instead of
burdering user with clarification requests.

Fix portions of the researcher prompt that had gone stale since moving
to tool use and making researcher more task (vs q&a) oriented
2025-08-11 22:28:47 -07:00
Debanjum
0a6d87067d Fix to have researcher let the coder tool write code
Previously the researcher was passing the whole code to execute in its
queries to the tool AI instead of asking it to write the code and
limiting its query to a natural language request (with required data).

The division of responsibility should help researcher just worry about
constructing a request with all the required details instead of also
worrying about writing correct code.
2025-08-11 22:28:47 -07:00