Search...
ctrl/
Light
Dark
System
Sign in
Environment:

How to set up Gel AI in EdgeQL

Gel AI brings vector search capabilities and retrieval-augmented generation directly into the database.

AI is a Gel extension. To enable it, we will need to add the extension to the app’s schema:

Copy
using extension ai;

Gel AI uses external APIs in order to get vectors and LLM completions. For it to work, we need to configure an API provider and specify their API key. Let's open EdgeQL REPL and run the following query:

Copy
configure current database
insert ext::ai::OpenAIProviderConfig {
  secret := 'sk-....',
};

Now our Gel application can take advantage of OpenAI's API to implement AI capabilities.

Gel AI comes with its own UI that can be used to configure providers, set up prompts and test them in a sandbox.

Most API providers require you to set up and account and charge money for model use.

One more feature Gel AI offers is built-in retrieval-augmented generation, also known as RAG.

Gel comes preconfigured to be able to process our text query, perform similarity search across the index we just created, pass the results to an LLM and return a response. We can access the built-in RAG using the /ai/rag HTTP endpoint:

Copy
$ 
curl --user user:password --json '{
    "query": "Who helps Komi make friends?",
    "model": "gpt-4-turbo-preview",
    "context": {"query":"select Friend"}
  }' http://localhost:<port>/branch/main/ai/rag

We can also stream the response like this:

Copy
  $ 
curl --user user:password --json '{
      "query": "Who helps Komi make friends?",
      "model": "gpt-4-turbo-preview",
      "context": {"query":"select Friend"},
+     "stream": true,
    }' http://localhost:<port>/branch/main/ai/rag

You are now sufficiently equipped to use Gel AI in your applications.

If you'd like to build something on your own, make sure to check out the Reference manual in order to learn the details about using different APIs and models, configuring prompts or using the UI. Make sure to also check out the Gel AI bindings in Python and JavaScript if those languages are relevant to you.

And if you would like more guidance for how Gel AI can be fit into an application, take a look at the FastAPI Gel AI Tutorial, where we're building a search bot using features you learned about above.