Context in Bag of words is associated with a data source. When connecting a data source, Bag of words will set the data source summary, its schema, and the set AI context and rules to the db and eventually to the LLM. When writing prompts, Bag of words will automatically add the right context (with prioritization) to the LLM request, to ensure the LLM will generate the best results.

When connecting a data source, Bag of words will use the data source summary and the set AI rules to generate the right data model and code to get the data. You can adjust the context and rules to tailor the data source to your needs and get the best results.

Data Source Summary


Bag of words will automatically generate a summary of the data source. You can adjust the summary to tailor the data source to your needs. A good summary will be concise, and include the most important information about the data source. For example, if you are connecting a product usage data source, a good summary would be:

This data source contains information about the usage of our product. It includes the number of users, the number of active users, and the number of sessions.
Key tables: users, sessions, products
Key relationships: users have many sessions, sessions have many products
Key metrics: active users, total users, total sessions, total products

AI Context


In addition to the data source summary, you can also set AI context. This is a set of rules that Bag of words will use to generate the data model and code. This is a place where you can be more specific and granular. Content can be sample queries, metrics, tables, relationships, rules, and more.

For example, you can set the following rules:

** Key tables and fields **
- table_a - represents users
- table_b - represents customers

** Example queries and code **
- SELECT * FROM table_a WHERE date > '2024-01-01'
- SELECT * FROM table_b order by date desc limit 10

** Data formatting requirements **
- Date is in EST time.
- Don't allow more than 5 columns in a query.

** Rules for using the data **
- Prioritize tables A and B.
- Use table C only if table A and B don't have the data you need.
- Always use left joins with table A.
- Always order by date desc.

Data Source Schema


The data source schema will be automatically added to the user prompt as part of the context. Schema is formatted as a DDL query. For example:

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255),
    email VARCHAR(255),
    created_at TIMESTAMP,
    updated_at TIMESTAMP
);

CREATE TABLE orders (
    id SERIAL PRIMARY KEY,
    user_id INT,
    order_date TIMESTAMP,
    total DECIMAL(10, 2),
    FOREIGN KEY (user_id) REFERENCES users(id)
);