AI & Search Modules

To enable AI in your application, the following modules are available to perform AI function calls. AI function are provided a prompt in the form of a string and returns its results.

Module: ai

To invoke an AI call, ai can be called with a prompt. For example:

//! Query AI with a maximum 128 tokens and 1.0 randomness in response
ai 128, 1.0, what is Pureflex?;
variable result = @@;
varlog AI response: {$result};

Combined with the other modules and utilities Pureflex provides, prompts can be tailored to your specific requirement. As an example:

//! Use the dataset recommended_books.csv containing a database of recommended books
setdata recommended_books.csv;

//! Create our database semantic vector search question 
variable question = "I am looking for a book in Military history, please recommend me an item.";

//! Instruct the app to search records relevant to the type of books in question
variable numberOfResults = 2;
datasearch {$numberOfResults},{$question};
variable searchResult | = @@;
variable preferredAnswer : = {$searchResult[0]};
variable answerDistance = {$preferredAnswer[1]};

//! Create the buffer to store AI response
variable aiResponse = ...;

//! Is the question relevant? If not, pass the question to the AI as a generic prompt.
condition more answerDistance 0.15;
    ai {$question};
    varchange aiResponse = @@;
    varlog {$aiResponse};

//! Transform the search results and allow ai to expand on the information
ai Given the question of {$question}, rephrase and add more information pertinent to the answers: {$searchResult};
varchange aiResponse = @@;

//! Print the results
varlog AI: {$aiResponse}; 

Text Model Compatibility & Streaming Mode

To use the the AI module without streaming-mode, a list of compatible text models must be set on the application. This list includes:

gpt-3.5 and up.

To take advantage of better quality response by using later version text models such as gpt-3.5-turbo, use streaming-mode like so:

//! Enable streaming mode using "continue!"

//! Streaming mode allows the AI to store memories of previous prompts.
ai descibe an animal in a simple sentence, any animal;
variable animal = @@;
varlog {$animal};
ai who are the predators of this animal?;
variable predators = @@;
varlog {$predators};

//! Disable the streaming mode using "end!";

Module: generate

For generative art production, the generate module can be used provided with a prompt describing the image to be created. For example:

generate a cat in a basket.
//! Prints:
//! image:cfe63dee-d7fb-4a0f-8171-421b3b00fd1a

In response, the type content and the file ID is provided delimited with : the file ID can be used to identify the file during file sharing in Interface Enabled Applications. To read more about Interfaces, see

Module: datasearch

Please ensure that your dataset is formatted with newlines to separate data with each line composed of a maximum of 2000 characters for embedding to work properly.

For faster dataset embedding, ensure that your data is structured properly - packed to as much as 2000 characters per line.

The datasearch allows for semantic vector search on one or multiple datasets. To upload a dataset, select the application in the dashboard and click Upload + under the Datasets section.

The currently supported formats for datasets are: .csv (text/csv), .txt (text/plain), .jsonl (text/jsonl) To create datasets please structure your data according to these file formats.

Currently the limit on datasets in Pureflex Early Access are limited to 200kb of data - this limited will be lifted in the future versions.

Datasearch Response

Performing a datasearch returns an array of results, each result includes: the content and the distance of the content against the given prompt. The distance of the result can be used to calculate the relevance of the result to the prompt.

//! Datasearch response results are separated by | - e.g. given a CSV formatteddata using ; as separator for columns "Question" and "Answer":

What is Purefle?;Pureflex is a micro-applications platform:0.1037752|
How can I use Pureflex?;To get started, create an account and an app.:0.20233

As per the example above, each result is separated using | and each values in the result are separated by : - the values can be extracted by assigning the result to an array variable in the application e.g.:

// Datasearch result parsing example
datasearch 2,What is pureflex?;

// Assign the result to an array variable
variable foundMatchingAnswers | = &&;

// Take the first answer and parse the values
variable preferredAnswer : = {$foundMatchingAnswers[0]};

// Take the distance of the first result
variable distance = {$preferredAnswer[1]};

// Is the answer relevant? If not, use it as a generic prompt.
condition equal_more distance 0.15;
	ai {$prompt};
	varchange aiResult = &&;
	varlog {$aiResult};

// If the answer is inded relevant, perform our transformation.
ai {$preferredAnswer} provided with this information as an answer to the question {$prompt}, rephrase the answer in a more smarter and professional form;
varchange aiResult = &&;
varlog {$aiResult};

Future Updates

More modules will be added in the future to advance the utility of AI for applications in Pureflex. Please stay up-to-date on our news for new module releases.


Let us know at [email protected]

Last updated