|
|
@ -62,10 +62,10 @@
|
|
|
|
"%pip install --upgrade --quiet langchain-core langchain-community\n",
|
|
|
|
"%pip install --upgrade --quiet langchain-core langchain-community\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"# Install Kineitca DB connection package\n",
|
|
|
|
"# Install Kineitca DB connection package\n",
|
|
|
|
"%pip install --upgrade --quiet gpudb typeguard\n",
|
|
|
|
"%pip install --upgrade --quiet 'gpudb>=7.2.0.8' typeguard pandas tqdm\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"# Install packages needed for this tutorial\n",
|
|
|
|
"# Install packages needed for this tutorial\n",
|
|
|
|
"%pip install --upgrade --quiet faker"
|
|
|
|
"%pip install --upgrade --quiet faker ipykernel "
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -114,7 +114,7 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 2,
|
|
|
|
"execution_count": 11,
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -139,11 +139,11 @@
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
" birthdate \n",
|
|
|
|
" birthdate \n",
|
|
|
|
"id \n",
|
|
|
|
"id \n",
|
|
|
|
"0 1997-12-01 \n",
|
|
|
|
"0 1997-12-08 \n",
|
|
|
|
"1 1924-07-27 \n",
|
|
|
|
"1 1924-08-03 \n",
|
|
|
|
"2 1933-11-28 \n",
|
|
|
|
"2 1933-12-05 \n",
|
|
|
|
"3 1988-10-19 \n",
|
|
|
|
"3 1988-10-26 \n",
|
|
|
|
"4 1931-03-12 \n"
|
|
|
|
"4 1931-03-19 \n"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
],
|
|
|
@ -222,39 +222,60 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 4,
|
|
|
|
"execution_count": 7,
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
"outputs": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
|
|
|
"text": [
|
|
|
|
|
|
|
|
"CREATE OR REPLACE CONTEXT \"demo\".\"test_llm_ctx\" (\n",
|
|
|
|
|
|
|
|
" TABLE = \"demo\".\"user_profiles\",\n",
|
|
|
|
|
|
|
|
" COMMENT = 'Contains user profiles.'\n",
|
|
|
|
|
|
|
|
"),\n",
|
|
|
|
|
|
|
|
"(\n",
|
|
|
|
|
|
|
|
" SAMPLES = ( \n",
|
|
|
|
|
|
|
|
" 'How many male users are there?' = 'select count(1) as num_users\n",
|
|
|
|
|
|
|
|
" from demo.user_profiles\n",
|
|
|
|
|
|
|
|
" where sex = ''M'';' )\n",
|
|
|
|
|
|
|
|
")\n"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
|
|
|
"text/plain": [
|
|
|
|
"1"
|
|
|
|
"1"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"execution_count": 4,
|
|
|
|
"execution_count": 7,
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"source": [
|
|
|
|
"# create an LLM context for the table.\n",
|
|
|
|
"from gpudb import GPUdbSamplesClause, GPUdbSqlContext, GPUdbTableClause\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"sql = f\"\"\"\n",
|
|
|
|
"table_ctx = GPUdbTableClause(table=table_name, comment=\"Contains user profiles.\")\n",
|
|
|
|
"CREATE OR REPLACE CONTEXT {kinetica_ctx}\n",
|
|
|
|
"\n",
|
|
|
|
"(\n",
|
|
|
|
"samples_ctx = GPUdbSamplesClause(\n",
|
|
|
|
" TABLE = {table_name}\n",
|
|
|
|
" samples=[\n",
|
|
|
|
" COMMENT = 'Contains user profiles.'\n",
|
|
|
|
|
|
|
|
"),\n",
|
|
|
|
|
|
|
|
" (\n",
|
|
|
|
" (\n",
|
|
|
|
" SAMPLES = (\n",
|
|
|
|
" \"How many male users are there?\",\n",
|
|
|
|
" 'How many male users are there?' = \n",
|
|
|
|
" f\"\"\"\n",
|
|
|
|
" 'select count(1) as num_users\n",
|
|
|
|
" select count(1) as num_users\n",
|
|
|
|
" from {table_name}\n",
|
|
|
|
" from {table_name}\n",
|
|
|
|
" where sex = ''M'';')\n",
|
|
|
|
" where sex = 'M';\n",
|
|
|
|
|
|
|
|
" \"\"\",\n",
|
|
|
|
" )\n",
|
|
|
|
" )\n",
|
|
|
|
"\"\"\"\n",
|
|
|
|
" ]\n",
|
|
|
|
|
|
|
|
")\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"context_sql = GPUdbSqlContext(\n",
|
|
|
|
|
|
|
|
" name=kinetica_ctx, tables=[table_ctx], samples=samples_ctx\n",
|
|
|
|
|
|
|
|
").build_sql()\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"count_affected = kinetica_llm.kdbc.execute(sql)\n",
|
|
|
|
"print(context_sql)\n",
|
|
|
|
|
|
|
|
"count_affected = kinetica_llm.kdbc.execute(context_sql)\n",
|
|
|
|
"count_affected"
|
|
|
|
"count_affected"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -273,7 +294,7 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 5,
|
|
|
|
"execution_count": 8,
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -334,7 +355,7 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 6,
|
|
|
|
"execution_count": 9,
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"source": [
|
|
|
@ -357,7 +378,7 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 7,
|
|
|
|
"execution_count": 10,
|
|
|
|
"metadata": {},
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -404,7 +425,7 @@
|
|
|
|
"name": "python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
|
|
|
"pygments_lexer": "ipython3",
|
|
|
|
"version": "3.8.19"
|
|
|
|
"version": "3.9.19"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat": 4,
|
|
|
|