# Search Embeddings

Let's consider an example of a robot that is the second part of the project "AI Chat With Own Document" (in the [first part](https://docs.sherparpa.ru/en/sherpa-rpa/sherpa-designer/primery-robotov/ai-chat-with-own-document/create-embeddings), the robot computed embeddings from fragments of the specified text file and recorded them in a CSV file). This robot uses previously obtained embeddings and the ChatGPT neural network to answer any questions about the content of the document. That is, when using this robot, any natural language queries can be entered, and the neural network will provide an answer based on the content of the document.

The project of the robot consists of a single diagram. Thus, to describe step by step, this robot works as follows:

1. Loads the CSV file created in the first part of the project with text fragments and their corresponding embeddings.
2. Opens a window for inputting a query.
3. Executes the user's query.
4. If the user entered a string (word), it retrieves embeddings for that string (word).
5. Sends a request to the GPT model.
6. Opens a window with the response to the request to the GPT model.
7. After that, it opens a window for inputting a query and executes the user's request.

The project diagram looks like this (for convenience, the blocks of the diagram are numbered):<br>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdAqvEZJ3KaQ8H16JlSOkgr4TcJrdtl6crZpNYDSxGKyEm1LE53JK4sdDsjbIrFbQEN8ku8DPKnLpxvsRyTEgpBBhaP6erkURcmJb5CCRoTkccifsN8s-SU8M6C1Ypb19Ub2O00ASq0lC8-yKFDDxZLChY?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfSLDcQoTB7-9ElrTwZUgiQ8Tg89lf1NEDhvDTeE41EZQifX9Z7sWtMeiBClageBYZGqQjA6SdVJ7xALx3sNIZB1rpnSp_B7pzrLvUUl-GUrWXylg-vHvV74cIvBnQ3GiaSZKIV9k83cPR-bd3VmVh40ODd?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

1. **Start Block** (any diagram begins with this block).
2. The "Load from CSV" block allows loading a Data Table from a CSV document. The following properties are specified for this block:

* File path (the path to the file from which the Data Table needs to be loaded);
* Separator (the separator character);
* Encoding (the file encoding).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfnsix4ZXfEEtwsm4RnZNddE0N6mMqw4s-M1n6njnVMrI93KAoHPBh-17ckRQyiL66G3tN_VibTUO0jhm6fvy-HgqgYpDCREVsSJY6FUYGX2_tmxJ0oTjlXffpERSLlTZ73cpCJ1FfrfVMahUccS_PQp-Qs?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

3. **Text Input Window Block** shows a modal window designed to receive information from the user. The following properties are specified for this block:

* Title (the text that will be reflected in the dialog window title);
* Message (the text that will be reflected inside the dialog window).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfOHLB8bYv11BDhsF68fggWdW20-01tPTQBoc7Hm4sL-CkboFI2qMb6RJZ7i35msfZYemJX92F-XpbqtLuycyceB4SZ8z_Lyy17Cxyzpake4gtEfZKVlSXlscTSd_hzMKsJZx8R-kmxth4CCaYaBMcjJ1ll?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

4. **Condition Block** checks the specified condition for truth, after which the execution of the scenario continues towards the "Yes" exit (if the condition is met) or towards the "No" exit (if the condition is not met).

The condition is recorded in the format: "variable" equals (==)/ greater than (>)/ less than (<) "value".

For example: $a == "Hello", that is, if the value of variable $a is equal to "Hello", then the exit is "Yes", otherwise – the exit is "No".

$Result > 5, that is, if the value of variable $Result is less than 5, then the exit is "Yes", otherwise – the exit is "No".

In this case, the condition is set as: $TextQuery.Length == 0. That is, if the length of the string is zero, then the exit is "Yes".

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeLnv36adJubnuarHFIvY7FtnBj1Jedp-HAKq3cKrUwBLqfyDK2lFvYZBzvIS2WV2uKz55u2s1u6cbvCcOYWq97NUULkNzD20-RtTL1I_rCMeHkpybZiBYGSRU7ELqC7YIcljV3_LE6rUF96nSjwgtFpw?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

5. **Get Embeddings Block** allows obtaining embeddings for a string or list of strings using the Open AI service. The following properties are specified for this block:

* Text (the input text for which embeddings will be calculated);
* Model (the neural network model for generating the response);
* Timeout (the maximum waiting time for a response in seconds).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXel5PCjUpfZmi-5nhkNz4PxAWPEgFHwEPnjONaVCQT24nY2Y1RBHe6UJBa2YPn91j1KvdFygbTNTjJiPkbpNkCSot2fWov0ONVgjLlCn2nIswSXyZYfo5_bqpkmiKcDbvyXWB4fZZT21kXQ38RPZZgwLhs?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

6. **Log Block** allows outputting arbitrary messages and/or variable values to the log during the robot's scenario execution. The property "Value" is specified for this block. A text constant is indicated in quotes, and the variable name starts with the symbol $. That is, this block logs the embeddings obtained from the user's string in the previous block.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcW3ZIV_cG-4s1HEp_ddsafzSDtp9yu0pz3paue9WTHCP_oMt872mj6maXyvQR8lOeTiEEqioQN8yk9MBVVZrRjOX88uoLz-ySkOmdxftXlwoxD5vhB2-3_qSBlPYqBdyeYBpw4fWZWAYAO7zu1ETVLgdFH?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

7. **Find Embeddings Block** searches for the most similar strings in the knowledge base, which is a table of objects and their embeddings, based on the given embedding query and returns the indices of these strings as a list sorted by descending similarity. The embeddings for both the query and the embeddings table being searched can be obtained using the Get Embeddings block. When the block is used for the first time, a vector database is built, which may take a long time. In subsequent calls to the block with the same "DB ID", the already created vector database will be used, and the speed of the block's operation increases significantly. The following properties are specified for this block:

* Query embedding (the embedding for which similar strings need to be found in the table);
* Knowledge base (the table in which the search will be conducted, one of the columns of which must contain embeddings, while other columns can contain any user data);
* Embeddings column (the index of the column from the table (default value is set to 1), specified in the "Knowledge base" property, where the embeddings are located);
* Number of results (the maximum number of result rows returned by the block from the knowledge base (default value is set to 5).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcevNZ4H30NPomOggFsGBuiUg2e_04IL4kGddp0qCF0m46BBrjkGCHjygNSRcmjF5aJnEAFxdWM-6nbhTFSu5GDOTMHSgu4Av9979I-k4ayiI8s4bL3ii24iSc4cyYf7XjIXYMgavNX122QAu_D115ptH0?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

8. **Assign Value to Variable Block** sets new values for one or more variables. In this case, two values are specified in the properties that need to be assigned to the variables: the variable $AIQuery should be assigned the value "Answer the question using only knowledge base listed below.\`nQuestion: {query}\`nKnowledge base: \`n{strresult}", and the variable $strresult – an empty value (for subsequent writing of the response to the user's query).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfXxOBQofWTwyfKjEC18VKqNd-oek3L1DHaZUzXQ6-1wbfa3CmpZeLIjREPfew81qGL3VHvUnO5YF7lItLoiTClu6efSHf75J7MW_rKHDt_Tp9fqhT9cxHOVcrZQB343hU7snLko0C2mOUUXVFHeNJh-n4?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

9. **For Each (List) Loop Block** iterates over all elements in the specified list.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXffjgJ8I97j5hW5qOomYtV9-KYianFSSVIDb0F4FwuqYK0JBwJqf-mityizF-s_fzgO6XIDxoorF8zM-5yOzFf60sNvCGiruPqjjIhlv8CMei_L95sbMyeFB85A-Fo5GoWt5NTFYm_bRr_Zpytkk2txbLNc?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

10. **Assign Value to Variable Block** sets new values for one or more variables. In this case, one value is specified in the properties that needs to be assigned to the variable.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfLSr8x5jK8yw9juNhCAmXryd4nEW7fxCRLNPUFwLg8ttu5ev3NlrxL022b_BN3OiF4sumSKias7cv-HrxbJ8rklQCsNeX-Fv08CNi5trrqyEWTLPge99U2HLWrPLNcm5ygoDFnVCHLbKQ9RJyf_-Yy7t6P?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

11. **Assign Value to Variable Block** sets new values for one or more variables. In this case, two values are specified in the properties that need to be assigned to the specified variables.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcbyxvYz6RkogsSrXe1nLvzCISGNe44_6VUeE20hTDI0wXneaalG6Dt3V3jrHUsdhG0RaotAxn2jXcoKuPcZWJmL5SNjzSp8kQQOn9ayMdR7B0YUt2ExMZ-cvKg4FVI7QVISWScHf6pTVx_ytFvvgcBdEQ?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

12. **Log Block** allows outputting arbitrary messages and/or variable values to the log during the robot's scenario execution. The property "Value" is specified for this block. A text constant is indicated in quotes, and the variable name starts with the symbol $. That is, this block logs the value of the variable $AIQuery (the resulting query to GPT). In turn, the variable $AIQuery includes the user's text and the Knowledge Base.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcg8zqQWeIurBNRqRZsN8jZe7yMtoO-zGoL-gAfLvTDQg3g1GzNsDpCdCJfzucsvaAoe0WDwUqae2IGRA4-ZRjGr2XJa78g6IsNZZ-opiUAENNXpevMY5u8eA4nJhbMvQUokQS5GTpjCeJzZDuGh7IKWTS2?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

13. **Request to GPT Model Block** allows sending requests to classic generative models from Open AI prior to ChatGPT and receiving a response. The following properties are specified for this block:

* Request (a request in natural language);
* Model (the model for generating text);
* Temperature (a decimal number from 0 to 1, indicating the degree of "randomness" or "creativity" of the result, where 0 is the least creative result and 1 is the most random);
* Timeout (the maximum waiting time for a response in seconds).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfs87PUP3qoXJNCjZ4rfCckgFus6xiKcwmJlm4dPY6vshzvLrgkbcJydslUeEv-fkT8yHeBIPLpTqaTsSBbyrvt4v7hpUGP0NHupy-PiDtK1gRW_8OqMYYmeSOB1D0I5yDSpmetBpyi7iM7yZIdhWdOe1it?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

14. **Message Window Block** shows the user a modal dialog window with a specified title, text, and set of buttons. The following properties are specified for this block:

* Title (the text that will be displayed in the dialog window title);
* Message (the variable that will be displayed inside the dialog window, in this case, it is the variable $Response, which is the response of the generative model to the request);
* Buttons (the buttons that will be available for the user to click).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfRqA6XSOIeQlGxO9tXCfdLQeo4-OSoiWcUAAee4IgxpJuGI1ower4_FOaTHcic1BybgajOVQxWBLw00y-LgdUolwcwadPSvXENbDCUAZq_Eiy3qmRf2oy2GZsmBPsU4vAjAA1dSNPHzUrdcZ6ECAagF_Ma?key=A0aTFSxqdqslY-UYAcmeGA" alt=""><figcaption></figcaption></figure>

\
15\. **End Block** (this block concludes the execution of the scenario or returns the subprocess diagram to the main process).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sherparpa.ru/en/sherpa-rpa/sherpa-designer/primery-robotov/ai-chat-with-own-document/search-embeddings.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
