Skip to content

Commit

Permalink
Still couldn't make bulk insert the way I wanted
Browse files Browse the repository at this point in the history
  • Loading branch information
diksipav committed Feb 27, 2025
1 parent d7b709c commit d192af4
Showing 1 changed file with 49 additions and 59 deletions.
108 changes: 49 additions & 59 deletions docs/intro/tutorials/ai_fastapi_searchbot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,18 @@ with semantic search-based cross-chat memory.
built-in UI at <http://127.0.0.1:8000/docs>_, or manually with ``curl``:

.. note::
To pretty-print results in this and all following cURL examples, you can use ``jq``, by piping the output to it.
`jq <https://jqlang.org/>`_ is a lightweight and flexible command-line JSON processor that, among other things, formats responses with proper indentation. However, using it is optional for this tutorial.

.. code-block:: bash
To pretty-print results in this and all following cURL examples, you can use ``jq``, by piping the output to it.
`jq <https://jqlang.org/>`_ is a lightweight and flexible command-line JSON processor that, among other things, formats responses with proper indentation. However, using it is optional for this tutorial.


.. code-block:: bash
$ curl -X 'GET' \
'http://127.0.0.1:8000/' \
-H 'accept: application/json'
$ curl -X 'GET' \
'http://127.0.0.1:8000/' \
-H 'accept: application/json'
{
"message":"Hello World"
}
{
"message":"Hello World"
}
.. edb:split-section::
Expand Down Expand Up @@ -957,57 +955,49 @@ In this tutorial we'll write queries using :ref:`EdgeQL <ref_intro_edgeql>` and
.. edb:split-section::
That concludes our User-related functionality. Next, we need to handle Chats and Messages. Since the process is quite similar to what we've just covered, we won't go into detail. Instead, you can implement these endpoints yourself as an exercise or simply copy the code below if you're in a rush.
That concludes our User-related functionality. Next, we need to handle Chats and Messages. Since the process is quite similar to what we've just covered, we won't go into detail. Instead, you can implement these endpoints yourself as an exercise or simply copy the following code if you're in a rush.
.. code-block:: bash
:class: collapsible
$ echo '
select Chat {
messages: { role, body, sources },
user := .<chats[is User],
} filter .user.name = <str>$username;' > app/queries/get_chats.edgeql &&
echo '
select Chat {
messages: { role, body, sources },
user := .<chats[is User],
} filter .user.name = <str>$username and .id = <uuid>$chat_id;' > app/queries/get_chat_by_id.edgeql &&
echo '
with new_chat := (insert Chat)
select (
update User filter .name = <str>$username
set {
chats := assert_distinct(.chats union new_chat)
}
) {
new_chat_id := new_chat.id
}' > app/queries/create_chat.edgeql &&
echo '
with
user := (select User filter .name = <str>$username),
chat := (
select Chat filter .<chats[is User] = user and .id = <uuid>$chat_id
)
select Message {
role,
body,
sources,
chat := .<messages[is Chat]
} filter .chat = chat;' > app/queries/get_messages.edgeql &&
echo '
with
user := (select User filter .name = <str>$username),
update Chat
filter .id = <uuid>$chat_id and .<chats[is User] = user
set {
messages := assert_distinct(.messages union (
insert Message {
role := <str>$message_role,
body := <str>$message_body,
sources := array_unpack(<array<str>>$sources)
}
))
}' > app/queries/add_message.edgeql
$ echo 'select Chat {
messages: { role, body, sources },
user := .<chats[is User],
} filter .user.name = <str>$username;' > app/queries/get_chats.edgeql && echo 'select Chat {
messages: { role, body, sources },
user := .<chats[is User],
} filter .user.name = <str>$username and .id = <uuid>$chat_id;' > app/queries/get_chat_by_id.edgeql && echo 'with new_chat := (insert Chat)
select (
update User filter .name = <str>$username
set {
chats := assert_distinct(.chats union new_chat)
}
) {
new_chat_id := new_chat.id
}' > app/queries/create_chat.edgeql && echo 'with
user := (select User filter .name = <str>$username),
chat := (
select Chat filter .<chats[is User] = user and .id = <uuid>$chat_id
)
select Message {
role,
body,
sources,
chat := .<messages[is Chat]
} filter .chat = chat;' > app/queries/get_messages.edgeql && echo 'with
user := (select User filter .name = <str>$username),
update Chat
filter .id = <uuid>$chat_id and .<chats[is User] = user
set {
messages := assert_distinct(.messages union (
insert Message {
role := <str>$message_role,
body := <str>$message_body,
sources := array_unpack(<array<str>>$sources)
}
))
}' > app/queries/add_message.edgeql
.. edb:split-section::
Expand Down

0 comments on commit d192af4

Please sign in to comment.