Commit Graph

4747 Commits

Author SHA1 Message Date
Debanjum
4012a6372f Fix pgvector docker image pull by using postgres 15 tag
We were previously relying on an older, unmaintained version of
pgvector docker image, ankane/pgvector.

Moving to new docker image requires selecting from tags based on the
pg major version (14, 15, 16 or 17).

This change uses pg15 tag to resolve image pull.
Note: we use postgres 15 for khoj docker images currently

Fixes #1154
2025-04-08 18:07:08 +05:30
Debanjum
19618605a5 Upgrade documentation packages 2025-04-07 20:07:10 +05:30
Debanjum
3fc1435cd1 Fix login to local admin panel without need to set KHOJ_DEBUG
Issue introduced in commit 5a3c7b1.

Usage of KHOJ_DOMAIN
---
KHOJ_DOMAIN is tri-state for local, official and other production deployments:
- If KHOJ_DOMAIN is unset (for local):
  - sets CSRF cookie to localhost
  - adds khoj.dev variants to ALLOWED_HOSTS, CSRF_TRUSTED_ORIGINS
  - adds app.khoj.dev variants to CORS origins
- If KHOJ_DOMAIN is set to empty (for official):
  - sets CSRF to khoj.dev
  - adds khoj.dev variants to ALLOWED_HOSTS, CSRF_TRUSTED_ORIGINS
  - adds app.khoj.dev variants to CORS origins
- If KHOJ_DOMAIN is set (for other prod deployments):
  - sets CSRF cookie to KHOJ_DOMAIN
  - adds KHOJ_DOMAIN variants to ALLOWED_HOSTS, CSRF_TRUSTED_ORIGINS
  - adds KHOJ_DOMAIN variants to CORS origins

Related #1137, #1152

Resolves #1123
2025-04-07 19:43:58 +05:30
Debanjum
ed70d2254e Suppress spurious RequestAborted ASGI errors on the admin panel
Unsure why this error triggers on every request to the Django admin
panel these days but all the requests are completing fine and the
client is clearly not aborting the request when the RequestAborted
exception is raised.

Suppress these errors for now via middleware to prevent them from
unnecessarily cluttering up the server logs and confusing folks.

Related #1152
2025-04-07 19:43:58 +05:30
Debanjum
353a4aa597 Upgrade pgvector to use the new official docker image
- ankane/pgvector has been deprecated in place of pgvector/pgvector
- use full path to image on docker.io for consistency
2025-04-07 19:43:58 +05:30
Debanjum
50508d97f9 Disable telemetry only via KHOJ_TELEMETRY_DISABLE environment variable
Do not unnecessarily overload usage of KHOJ_DEBUG environment variable
2025-04-07 19:43:58 +05:30
sabaimran
2ae8c62547 Repopulate the client API-key generation section 2025-04-07 06:54:47 -07:00
Debanjum
6872817d41 Remove request to set default chat model during interactive init
It wasn't being set correctly and seems unnecessary as can switch
to desired chat models via the settings page or chat side pane easily
2025-04-07 14:38:55 +05:30
Debanjum
0c257c044e Handle unset response_schema being passed to gemini models 2025-04-05 23:12:35 +05:30
Debanjum
c1912f8ca7 Default eval to use 10 iterations for research mode 2025-04-05 10:09:58 +05:30
Debanjum
645c2bc546 Improve Khoj is ready message 2025-04-05 10:09:28 +05:30
Debanjum
6e61ec64a4 Release Khoj version 1.39.0 2025-04-04 20:35:50 +05:30
Debanjum
751215a701 Improve response quality with Gemini. Improve evaluation harness (#1150)
### Improve Gemini usage
- Allow text tool to give agent ability to terminate research
- Set default context for gemini 2 flash models
  2x context window for small, commercial models to 120K
- Default temperature of Gemini models to 1.0 to reduce repetition

### Improve evaluation harness
- Add more knobs to control eval workflow
  - Allow running eval with any chat model served over an openai compatible api
  - Control random sampling from eval set
  - Auto read web page
- Use embedded postgres instead of postgres server for eval workflow
- Use Gemini 2.0 flash as evaluator. Set seed for evaluator to reduce decision variance
2025-04-04 20:17:36 +05:30
Debanjum
7f18bc0840 Add default context for gemini 2 flash. 2x it for small, commercial models
Previously Gemini 2 flash and flash lite were using context window of
10K by default as no defaults were added for it.

Increase default context for small commercial models to 120K from 60K
as cheaper and faster than their pro models equivalents at 60K context.
2025-04-04 20:11:00 +05:30
Debanjum
47a081c7bd Allow text tool to give agent ability to terminate research
We'd moved research planner to only use tools in enum of schema. This
enum tool enforcement prevented model from terminating research by
setting tool field to empty.

Fix the issue by adding text tool to research tools enum and tell
model to use that to terminate research and start response instead.
2025-04-04 20:11:00 +05:30
Debanjum
38dd02afbf Make ordering of fields expected by research planner consistent
Make research planner consistently select tool before query. As the
model should tune it's query for the selected tool. It got space to
think about tool to use in the scratchpad already.
2025-04-04 20:11:00 +05:30
Debanjum
443c5a4420 Consistently wrap queries in online search prompt in double quotes
The queries field name in the first example isn't wrapped in double
quotes, rest are.
2025-04-04 20:11:00 +05:30
Debanjum
ae8fb6f9ac Default temperature of Gemini models to 1.0 to try avoid repetition
This is the default temperature for non-thinking gemini models on ai
studio. See if using this alleviates the problem.
2025-04-04 20:11:00 +05:30
Debanjum
e9928d3c50 Eval more model, control randomization & auto read webpage via workflow
- Control auto read webpage via eval workflow. Prefix env var with KHOJ_
  Default to false as it is the default that is going to be used in prod
  going forward.

- Set openai api key via input param in manual eval workflow runs
  - Simplify evaluating other chat models available over openai
    compatible api via eval workflow.
  - Mask input api key as secret in workflow.
  - Discard unnecessary null setting of env vars.

- Control randomization of samples in eval workflow.
  If randomization is turned off, it'll take the first SAMPLE_SIZE
  items from the eval dataset instead of a random collection of
  SAMPLE_SIZE items.
2025-04-04 20:11:00 +05:30
Debanjum
911e1bf981 Use gemini 2.0 flash as evaluator. Set seed for it to reduce eval variance.
Gemini 2.0 flash model is cheaper and better than Gemini 1.5 pro
2025-04-04 20:11:00 +05:30
Debanjum
0dcb2544d7 Use embedded postgres instead of postgres server for eval workflow 2025-04-04 20:11:00 +05:30
sabaimran
abfdf7b1fb Temporarily remove the OTP feature on the settings page while we fix our number 2025-04-03 19:41:18 -05:00
Artem Yurchenko
1ef8c37c3a Implement better template for feature request issue (#1132)
This PR implements a new feature request template with a few UX/UI improvements.

Key changes:
- Use of GitHub forms.
- Provide note info for a submitter about feature request submitting rules.
- Adds a few handy fields like "Describe the feature" or "Use Case"

Overall, with a template like this feature requests will be more structured and meaningful.
2025-04-03 15:41:04 +05:30
Debanjum
17997d26c5 Make generated code block extractor less strict to improve code tool 2025-04-03 14:07:15 +05:30
Debanjum
66e9ddb6be Support OpenAI (API compatible) models and Firecrawl in eval workflow 2025-04-03 14:03:29 +05:30
Debanjum
ef5b19479f Improve setup of openai compatible speech to text, image models
Only setup speech to text and text to image models served via openai
compatible APIs when explicitly specified during initialization.

This avoids setup of whisper and dalle when an openai compatible API
is being setup instead of the openai API itself.
2025-04-03 13:44:19 +05:30
Debanjum
c2b9006a7a Improve Gemini Response Reliability (#1148)
- Specify min, max number of list items expected in AI response via JSON schema enforcement. Used by Gemini models
- Warn and drop invalid/empty messages when format messages for Gemini models
- Make Gemini response adhere to the order of the schema property definitions
- Improve agent creation safety checker by using response schema, better prompt
2025-04-03 13:42:35 +05:30
Debanjum
f77e871cc8 Improve agent creation safety checker with response schema, better prompt 2025-04-03 02:49:40 +05:30
Debanjum
aab010723c Make Gemini response adhere to the order of the schema property definitions
Without explicitly using the property ordering field, gemini returns
responses in alphabetically sorted property order.

We want the model to respect the schema property definition order.
This ensures control during development to maintain response quality.

For example in CoT make it fill scratchpad before answers.
2025-04-03 01:19:48 +05:30
Debanjum
ae9ca58ab9 Specify min, max items expected in ai response via schema enforcement
Require at least 1 item in lists. Otherwise gemini flash will
sometimes return an empty list. For chat actors where max items is
known, set that as well.

OpenAI API does not support specifying min, max items in response
schema lists, so drop those properties when response schema is
passed. Add other enforcements to response schema to comply with
response schema format expected by OpenAI API.
2025-04-03 01:19:39 +05:30
Debanjum
0eb2d17771 Warn and drop invalid messages when format messages for gemini
Previously we were setting message content part with empty text. This
results in error from Gemini API. Warn and drop such messages instead.

Log empty message content found during construction to root-cause the
issue but allow Khoj to respond without the offending messages in
context for call to Gemini API.
2025-04-03 01:11:22 +05:30
sabaimran
dd957bedd3 Remove pgserver in repo from git tracking 2025-03-31 15:07:24 -05:00
sabaimran
d53b740197 Improve online search and allow server to skip auto webpage read 2025-03-31 13:52:48 -05:00
Debanjum
177560655d Fix and Improve Online Search and Webpage Read (#1147)
New
- Support Firecrawl as a online search provider

Improve
- Fallback to other enabled online search providers on failure
- Speed up online search with Jina by excluding webpage content in search results

Fix
- Fix Jina webpage reader. Improve it to include generated alt text to each image on webpage
- Truncate online query to Serper if query exceeds max supported length
2025-04-01 00:09:46 +05:30
Debanjum
d62dd4ef61 Support Firecrawl as a online search provider 2025-03-31 17:06:00 +05:30
Debanjum
3939e995e4 Fallback to enabled, lower priority online search providers on error
Make serper.dev higher priority than official google serp api because
it provides more detailed results with knowledge cards etc.
2025-03-31 17:05:44 +05:30
Debanjum
9b7442f28f Truncate online query to Serper if query exceeds max supported length
Previously query to serper with longer than max supported would throw
error instead of returning at least some results.

Truncating the onlien search query to serper to max supported length
mitigates that issue.
2025-03-31 17:01:42 +05:30
Debanjum
db7eba56f6 Fix webpage read and improve web search with Jina
- Improve webpage read to include image alt text
- Improve Jina webpage search to not include each page content
- Use POST instead of GET for web search, webpage read with Jina
2025-03-31 17:01:42 +05:30
Debanjum
db68372b81 Update code sandbox prompts to allow network access when using E2B
Tell Khoj code writing chat actor that it has access to the network
and can use the python requests library in the E2B code sandbox.
2025-03-31 15:33:47 +05:30
Debanjum
5b8c2989d6 Add hover text on button to unshare a conversation on web app 2025-03-31 15:32:43 +05:30
Debanjum
85d627ceb0 Simplify docs to self-host with pip since can use embedded DB now
Remove postgres setup instructions from self host with pip docs. It is
unnecessary if embedded postgres DB works on the operating system.
2025-03-30 00:17:24 +05:30
Debanjum
713ba06a8d Release Khoj version 1.38.0 2025-03-29 18:30:06 +05:30
Debanjum
e9132d4fee Support attaching programming language file types to web app for chat 2025-03-29 01:22:35 +05:30
Debanjum
bdb6e33108 Install pgserver only when `pip install khoj[local]' is enabled
This avoids installing pgserver on linux arm64 docker builds, which it
doesn't currently support and isn't required to support as Khoj docker
images can use standard postgres server made available via our
docker-compose.yml
2025-03-29 00:27:19 +05:30
Debanjum
5ee513707e Use embedded postgres db to simplify self-hosted setup (#1141)
Use pgserver python package as an embedded postgres db,
installed directly as a khoj python package dependency.

This significantly simplifies self-hosting with just a `pip install khoj'. 
No need to also install postgres separately.

Still use standard postgres server for multi-user, production use-cases.
2025-03-29 00:03:55 +05:30
Debanjum
56b63f95ea Suggest Google image gen model, new Anthropic chat models on first run
- Update default anthropic chat models to latest good models.

- Now that Google supports a good text to image model. Suggest adding
  that if Google AI API is setup on first run.
2025-03-28 23:07:17 +05:30
Ikko Eltociear Ashimine
1e34de69e9 Fix spelling in Automations Docs (#1140)
Recieve -> Receive
2025-03-28 23:07:06 +05:30
Debanjum
72986c905a Fix default agent creation to allow chat on first run
Previously agent slug was not considered on create even when passed
explicitly in agent creation step.

This made the default agent slug different until next run when it was
updated after creation. And didn't allow chat to work on first run

The fix to use the agent slug when explicitly passed allows users to
chat on first run.
2025-03-28 22:49:00 +05:30
Debanjum
03de2803f0 Fallback to default agent for chat when unset in get conversation API 2025-03-28 00:56:18 +05:30
Debanjum
a387f638cd Enforce json schema on more chat actors to improve schema compliance
Including infer webpage urls, gemini documents search, pick default
mode tools chat actors
2025-03-28 00:56:18 +05:30