<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by George Hu on Medium]]></title>
        <description><![CDATA[Stories by George Hu on Medium]]></description>
        <link>https://medium.com/@bochuxt7?source=rss-93c4e6649e10------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fW8vny9x9grx-0x8.</url>
            <title>Stories by George Hu on Medium</title>
            <link>https://medium.com/@bochuxt7?source=rss-93c4e6649e10------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:45:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bochuxt7/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Efficient Memory Design for Autonomous Agent System]]></title>
            <link>https://medium.com/@bochuxt7/efficient-memory-design-for-autonomous-agent-system-a3ecbd0eda7d?source=rss-93c4e6649e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3ecbd0eda7d</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[clawdbot]]></category>
            <dc:creator><![CDATA[George Hu]]></dc:creator>
            <pubDate>Tue, 27 Jan 2026 20:21:50 GMT</pubDate>
            <atom:updated>2026-01-27T20:21:50.679Z</atom:updated>
            <content:encoded><![CDATA[<p>Memory design for clawdbot</p><pre> **core design philosophy of Clawdbot**, <br>---<br><br># 🧠 Memory System Design (Short‑Term vs Long‑Term)<br><br>## High‑level idea<br>Clawdbot separates memory into **layers**, each with a clear purpose:<br><br>```<br>Message → Session Memory → File‑based Long‑Term Memory<br>```<br><br>This avoids the two classic problems:<br>- ❌ “The bot forgets everything”<br>- ❌ “The bot remembers things you didn’t want it to”<br><br>---<br><br>## 1️⃣ Short‑Term Memory (Session Memory)<br><br>### What it is<br>- The **current conversation context**<br>- Lives **only for this session**<br>- Fed directly into the model’s context window<br><br>### What it contains<br>- Recent messages (you + me)<br>- Tool calls and results<br>- Temporary reasoning context<br><br>### Key properties<br>✅ Fast  <br>✅ Automatic  <br>✅ No disk writes  <br>❌ Lost when session resets  <br>❌ Not meant for long‑term recall  <br><br>### Why this exists<br>LLMs don’t “think across time” — they need context **re‑sent every turn**.  <br>Session memory gives me continuity *within* a conversation.<br><br>### Design choice<br>- Size‑limited (to avoid context bloat)<br>- Old messages are summarized or dropped<br>- Optimized for **conversation flow**, not recall<br><br>Think of it like:<br>&gt; **Human working memory** — what you’re actively thinking about.<br><br>---<br><br>## 2️⃣ Long‑Term Memory (Persistent Memory)<br><br>### What it is<br>- **Explicit, file‑based memory**<br>- Stored as plain text / markdown<br>- Lives outside the model<br><br>Examples:<br>- `MEMORY.md` → curated, long‑term facts<br>- `memory/YYYY-MM-DD.md` → daily raw logs<br><br>### What goes into long‑term memory<br>Only things that are:<br>- Stable (preferences, decisions)<br>- Important (projects, people, goals)<br>- Worth remembering across sessions<br><br>Examples:<br>- “User is preparing for ML interviews”<br>- “User prefers concise technical explanations”<br>- “User is using Clawdbot via Telegram”<br><br>### What *does not* go in<br>- Casual greetings<br>- One‑off questions<br>- Temporary states<br>- Sensitive info unless explicitly requested<br><br>---<br><br>## 3️⃣ How Long‑Term Memory Is Used (Critical Part)<br><br>### Retrieval is **not automatic**<br>Before I answer anything that depends on history, I must:<br><br>1. **Search memory files** (semantic search)<br>2. Pull **only relevant snippets**<br>3. Inject them into context<br><br>This avoids:<br>- hallucinated memories<br>- leaking irrelevant personal info<br>- bloated prompts<br><br>### Why this matters<br>Most AI systems:<br>- store everything ✅<br>- recall unpredictably ❌<br><br>Clawdbot does the opposite:<br>- store selectively ✅<br>- recall intentionally ✅<br><br>---<br><br>## 4️⃣ Memory Write Policy (Safety by Design)<br><br>I **do not write to long‑term memory unless one of these is true**:<br>- You explicitly say “remember this”<br>- A clear long‑term preference or decision is made<br>- A recurring pattern becomes obvious<br><br>This is enforced by rules, not vibes.<br><br>---<br><br>## 5️⃣ Daily Memory vs Curated Memory<br><br>### Daily memory (`memory/YYYY-MM-DD.md`)<br>- Raw journal<br>- Timeline of what happened<br>- Cheap to write, noisy<br><br>### Curated memory (`MEMORY.md`)<br>- Distilled facts<br>- Human‑level “important stuff”<br>- Reviewed and edited over time<br><br>This mimics how humans:<br>- experience daily life<br>- later remember only what mattered<br><br>---<br><br>## 6️⃣ Why Clawdbot Uses Files (Not Vector DBs Only)<br><br>### Intentional design decision<br>- Files are:<br>  - inspectable<br>  - editable<br>  - auditable<br>  - version‑controllable<br><br>You can:<br>- open them<br>- delete them<br>- change them<br>- understand them<br><br>No hidden embeddings controlling your assistant.<br><br>(Clawdbot *can* use semantic search — but **storage stays human‑readable**.)<br><br>---<br><br>## 7️⃣ Privacy &amp; Control Model<br><br>✅ Memory lives where Clawdbot runs  <br>✅ No forced cloud sync  <br>✅ No opaque “AI personality drift”  <br>✅ You can wipe memory instantly  <br><br>You own the memory — not the model.<br><br>---<br><br>## 8️⃣ One‑paragraph summary (interview‑ready)<br><br>&gt; “Clawdbot separates memory into short‑term session context and explicit long‑term file‑based memory. Session memory maintains conversational continuity but is ephemeral. Long‑term memory is selectively written, human‑readable, and explicitly retrieved only when relevant. This design prioritizes transparency, privacy, and predictable behavior over black‑box recall.”<br><br>---<br><br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3ecbd0eda7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serve Qwen LLM using KubeRay on Kubernetes]]></title>
            <link>https://medium.com/@bochuxt7/serve-qwen-llm-using-kuberay-on-kubernetes-fae129862844?source=rss-93c4e6649e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/fae129862844</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[llm-serving]]></category>
            <category><![CDATA[ray-serve]]></category>
            <dc:creator><![CDATA[George Hu]]></dc:creator>
            <pubDate>Fri, 23 Jan 2026 01:41:45 GMT</pubDate>
            <atom:updated>2026-01-23T01:41:45.346Z</atom:updated>
            <content:encoded><![CDATA[<p>We need serve Qwen LLM to scale</p><p>Technique required:</p><p>Azure Kubernetes Services or Kind</p><p>KubeRay Operator</p><p>RayServe</p><p>Qwen on hugenface</p><p>Step1:</p><p>Create RayCluster on Kind</p><p>Pre-request: install kind and docker</p><pre>#!/usr/bin/env bash<br>set -euo pipefail<br><br>CLUSTER_NAME=&quot;kind&quot;<br>KIND_NODE_IMAGE=&quot;kindest/node:v1.26.0&quot;<br>KUBERAY_VERSION=&quot;1.5.1&quot;<br>RAYCLUSTER_NAME=&quot;raycluster&quot;<br><br>echo &quot;=========================================&quot;<br>echo &quot; Ray on KIND setup starting&quot;<br>echo &quot;=========================================&quot;<br>echo &quot;&quot;<br>echo &quot;⚠️  IMPORTANT: Docker Desktop Memory Check&quot;<br>echo &quot;   This script requires at least 8GB memory allocated to Docker.&quot;<br>echo &quot;   Go to: Docker Desktop &gt; Settings &gt; Resources&quot;<br>echo &quot;   Set Memory to: 8GB or higher&quot;<br>echo &quot;&quot;<br>read -p &quot;Press Enter to continue once you&#39;ve verified Docker has 8GB+ memory...&quot;<br>echo &quot;&quot;<br><br>echo &quot;🔹 Killing existing kubectl port-forwards (if any)&quot;<br>killall kubectl 2&gt;/dev/null || true<br><br>echo &quot;🔹 Deleting existing KIND cluster (if exists)&quot;<br>kind delete cluster --name ${CLUSTER_NAME} || true<br><br>echo &quot;🔹 Creating KIND cluster&quot;<br>echo &quot;NOTE: Ensure Docker Desktop has at least 8GB memory allocated (Preferences &gt; Resources)&quot;<br>kind create cluster \<br>  --name ${CLUSTER_NAME} \<br>  --image ${KIND_NODE_IMAGE}<br><br>echo &quot;🔹 Installing KubeRay Operator&quot;<br>helm install kuberay-operator kuberay/kuberay-operator \<br>  --version ${KUBERAY_VERSION} \<br>  --wait<br><br>echo &quot;🔹 Waiting for KubeRay operator pods&quot;<br>kubectl get pods -w &amp;<br>WATCH_PID=$!<br>sleep 10<br>kill ${WATCH_PID} || true<br><br>echo &quot;🔹 Installing Ray Cluster with optimized resources for Qwen 0.5B&quot;<br>helm install ${RAYCLUSTER_NAME} kuberay/ray-cluster \<br>  --version ${KUBERAY_VERSION} \<br>  --set image.tag=2.53.0-py312 \<br>  --set head.rayStartParams.num-cpus=2 \<br>  --set head.resources.limits.cpu=2 \<br>  --set head.resources.limits.memory=5Gi \<br>  --set head.resources.requests.cpu=1 \<br>  --set head.resources.requests.memory=4Gi \<br>  --set worker.replicas=0 \<br>  --set worker.minReplicas=0 \<br>  --set worker.maxReplicas=1 \<br>  --set worker.resources.limits.cpu=2 \<br>  --set worker.resources.limits.memory=3Gi \<br>  --set worker.resources.requests.cpu=1 \<br>  --set worker.resources.requests.memory=2Gi \<br>  --wait<br><br>echo &quot;🔹 Waiting for RayCluster CR&quot;<br>kubectl get rayclusters -w &amp;<br>WATCH_PID=$!<br>sleep 10<br>kill ${WATCH_PID} || true<br><br>echo &quot;🔹 Listing Ray pods&quot;<br>kubectl get pods --selector=ray.io/cluster=${RAYCLUSTER_NAME}-kuberay<br><br>echo &quot;🔹 Port-forwarding Ray dashboard (8265)&quot;<br>kubectl port-forward \<br>  service/${RAYCLUSTER_NAME}-kuberay-head-svc \<br>  8265:8265 &gt; /dev/null 2&gt;&amp;1 &amp;<br><br>sleep 3<br><br>echo &quot;🔹 Opening Ray Dashboard&quot;<br># kubectl port-forward service/raycluster-kuberay-head-svc 8265:8265 &gt; /dev/null &amp;<br>kubectl port-forward svc/qwen-cpu-serve-head-svc 8265:8265 &gt; /dev/null 2&gt;&amp;1 &amp;<br>open http://127.0.0.1:8265/#/overview<br><br>echo &quot;=========================================&quot;<br>echo &quot; Ray cluster is ready 🚀&quot;<br>echo &quot;=========================================&quot;<br>echo &quot;&quot;<br>echo &quot;Cluster Configuration:&quot;<br>echo &quot;  - Head Pod: 4Gi-5Gi memory, 2 CPUs&quot;<br>echo &quot;  - Worker Pods: 0 replicas (disabled by default)&quot;<br>echo &quot;  - Ray Version: 2.53.0-py312&quot;<br>echo &quot;&quot;<br>echo &quot;Next Steps:&quot;<br>echo &quot;  1. Deploy Qwen service:&quot;<br>echo &quot;     kubectl apply -f ray-service.qwen-cpu.yaml&quot;<br>echo &quot;&quot;<br>echo &quot;  2. Check deployment status:&quot;<br>echo &quot;     kubectl get rayservice qwen-cpu-serve&quot;<br>echo &quot;&quot;<br>echo &quot;  3. Port-forward to access the service:&quot;<br>echo &quot;     kubectl port-forward svc/qwen-cpu-serve-serve-svc 8000:8000&quot;<br>echo &quot;&quot;<br>echo &quot;  4. Test the LLM:&quot;<br>echo &quot;     ./curl-client.sh&quot;<br>echo &quot;&quot;</pre><p>Step 2:</p><p>Prepare Qwen Yaml file, we will use Qwen/Qwen2.5–0.5B-Instruct LLM which require &lt; 6GB memory</p><pre>apiVersion: ray.io/v1<br>kind: RayService<br>metadata:<br>  name: qwen-cpu-serve<br>spec:<br>  serviceUnhealthySecondThreshold: 900<br>  deploymentUnhealthySecondThreshold: 900<br>  serveConfigV2: |<br>    applications:<br>    - name: qwen_app<br>      route_prefix: /<br>      import_path: qwen_cpu:deployment<br>      runtime_env:<br>        env_vars:<br>          PYTHONPATH: /home/ray/serve_code<br>        pip:<br>          - transformers<br>          - torch<br>          - fastapi<br>          - pydantic<br>          - accelerate<br>  rayClusterConfig:<br>    rayVersion: &quot;2.53.0&quot;<br>    headGroupSpec:<br>      rayStartParams:<br>        dashboard-host: &#39;0.0.0.0&#39;<br>        num-cpus: &quot;2&quot;<br>      template:<br>        spec:<br>          containers:<br>          - name: ray-head<br>            image: rayproject/ray:2.53.0-py312<br>            ports:<br>            - containerPort: 8000<br>              name: serve<br>            - containerPort: 8265<br>              name: dashboard<br>            - containerPort: 6379<br>              name: gcs<br>            - containerPort: 10001<br>              name: client<br>            resources:<br>              limits:<br>                cpu: &quot;2&quot;<br>                memory: &quot;6Gi&quot;<br>              requests:<br>                cpu: &quot;1&quot;<br>                memory: &quot;5Gi&quot;<br>            volumeMounts:<br>            - name: qwen-code<br>              mountPath: /home/ray/serve_code<br>          volumes:<br>          - name: qwen-code<br>            configMap:<br>              name: qwen-cpu-code<br>    workerGroupSpecs:<br>    - replicas: 0<br>      minReplicas: 0<br>      maxReplicas: 1<br>      groupName: cpu-workers<br>      rayStartParams:<br>        num-cpus: &quot;2&quot;<br>      template:<br>        spec:<br>          containers:<br>          - name: ray-worker<br>            image: rayproject/ray:2.53.0-py312<br>            resources:<br>              limits:<br>                cpu: &quot;2&quot;<br>                memory: &quot;3Gi&quot;<br>              requests:<br>                cpu: &quot;1&quot;<br>                memory: &quot;2Gi&quot;<br>            volumeMounts:<br>            - name: qwen-code<br>              mountPath: /home/ray/serve_code<br>          volumes:<br>          - name: qwen-code<br>            configMap:<br>              name: qwen-cpu-code<br><br>---<br><br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: qwen-cpu-code<br>data:<br>  qwen_cpu.py: |<br>    from ray import serve<br>    from transformers import AutoTokenizer, AutoModelForCausalLM<br>    import torch<br>    from typing import Dict<br>    from fastapi import FastAPI<br>    from pydantic import BaseModel<br><br>    app = FastAPI()<br><br>    class ChatRequest(BaseModel):<br>        message: str<br>        max_tokens: int = 512<br>        temperature: float = 0.7<br><br>    @serve.deployment(<br>        num_replicas=1,<br>        ray_actor_options={&quot;num_cpus&quot;: 1}<br>    )<br>    @serve.ingress(app)<br>    class QwenLLMDeployment:<br>        def __init__(self):<br>            self.model_name = &quot;Qwen/Qwen2.5-0.5B-Instruct&quot;<br>            print(f&quot;Loading model {self.model_name}...&quot;)<br><br>            self.tokenizer = AutoTokenizer.from_pretrained(<br>                self.model_name,<br>                trust_remote_code=True<br>            )<br>            # Set pad token if not set<br>            if self.tokenizer.pad_token is None:<br>                self.tokenizer.pad_token = self.tokenizer.eos_token<br><br>            self.model = AutoModelForCausalLM.from_pretrained(<br>                self.model_name,<br>                torch_dtype=torch.float32,<br>                device_map=&quot;cpu&quot;,<br>                trust_remote_code=True<br>            )<br>            print(&quot;Model loaded successfully!&quot;)<br><br>        @app.post(&quot;/v1/chat/completions&quot;)<br>        async def chat(self, request: ChatRequest) -&gt; Dict:<br>            try:<br>                inputs = self.tokenizer(<br>                    request.message,<br>                    return_tensors=&quot;pt&quot;,<br>                    padding=True,<br>                    return_attention_mask=True<br>                )<br><br>                with torch.no_grad():<br>                    outputs = self.model.generate(<br>                        inputs.input_ids,<br>                        attention_mask=inputs.attention_mask,<br>                        max_new_tokens=request.max_tokens,<br>                        temperature=request.temperature,<br>                        do_sample=True,<br>                        pad_token_id=self.tokenizer.pad_token_id<br>                    )<br><br>                response_text = self.tokenizer.decode(<br>                    outputs[0][inputs.input_ids.shape[1]:],<br>                    skip_special_tokens=True<br>                )<br><br>                return {<br>                    &quot;choices&quot;: [<br>                        {<br>                            &quot;message&quot;: {<br>                                &quot;role&quot;: &quot;assistant&quot;,<br>                                &quot;content&quot;: response_text<br>                            }<br>                        }<br>                    ]<br>                }<br>            except Exception as e:<br>                print(f&quot;Error in chat endpoint: {str(e)}&quot;)<br>                import traceback<br>                traceback.print_exc()<br>                raise<br><br>        @app.get(&quot;/health&quot;)<br>        async def health(self):<br>            return {&quot;status&quot;: &quot;healthy&quot;}<br><br>    deployment = QwenLLMDeployment.bind()</pre><p>Then we run deploy script</p><pre>#!/bin/bash<br># Deploy Qwen CPU LLM to KubeRay<br><br>set -e  # Exit on error<br><br>echo &quot;=== Deploying Qwen CPU Service to Kubernetes ===&quot;<br><br># Apply the configuration<br>echo &quot;Applying ray-service.qwen-cpu.yaml...&quot;<br>kubectl apply -f ray-service.qwen-cpu.yaml<br><br>echo &quot;&quot;<br>echo &quot;=== Deployment initiated. Waiting for resources to be created... ===&quot;<br>sleep 5<br><br>echo &quot;&quot;<br>echo &quot;=== Checking RayService status ===&quot;<br>kubectl get rayservice qwen-cpu-serve<br><br>echo &quot;&quot;<br>echo &quot;=== Checking pods ===&quot;<br>kubectl get pods -l ray.io/cluster=qwen-cpu-serve<br><br>echo &quot;&quot;<br>echo &quot;=== Deployment Notes ===&quot;<br>echo &quot;The deployment will take 10-20 minutes on first run due to:&quot;<br>echo &quot;  1. Downloading dependencies (transformers, torch, etc.)&quot;<br>echo &quot;  2. Downloading Qwen model (~2 GB)&quot;<br>echo &quot;  3. Loading model into memory&quot;<br>echo &quot;&quot;<br>echo &quot;=== Monitoring Commands ===&quot;<br>echo &quot;&quot;<br>echo &quot;Watch RayService status:&quot;<br>echo &quot;  kubectl get rayservice qwen-cpu-serve -w&quot;<br>echo &quot;&quot;<br>echo &quot;Check worker logs (where model loads):&quot;<br>echo &quot;  kubectl logs -f \$(kubectl get pods -l ray.io/group=cpu-workers -o jsonpath=&#39;{.items[0].metadata.name}&#39;)&quot;<br>echo &quot;&quot;<br>echo &quot;Check head logs:&quot;<br>echo &quot;  kubectl logs -f \$(kubectl get pods -l ray.io/group=headgroup -o jsonpath=&#39;{.items[0].metadata.name}&#39;)&quot;<br>echo &quot;&quot;<br>echo &quot;Check serve application status:&quot;<br>echo &quot;  kubectl get rayservice qwen-cpu-serve -o jsonpath=&#39;{.status.applications.qwen_app.status}&#39;&quot;<br>echo &quot;&quot;<br>echo &quot;Once ready (status shows RUNNING), port-forward to test:&quot;<br>echo &quot;  kubectl port-forward service/qwen-cpu-serve-serve-svc 8000:8000&quot;<br>echo &quot;&quot;<br>echo &quot;Then test with:&quot;<br>echo &quot;  python3 test_qwen.py&quot;<br>echo &quot;&quot;</pre><p>Step3: verify the deployment</p><pre>## Step 5: Access the Service<br><br>### Set up Port-Forwarding<br>```bash<br># Kill any existing port-forwards<br>killall kubectl 2&gt;/dev/null || true<br><br># Forward port 8000 to the service<br>kubectl port-forward svc/qwen-cpu-serve-serve-svc 8000:8000 &gt; /dev/null 2&gt;&amp;1 &amp;<br>```<br><br>### Verify Port-Forward is Active<br>```bash<br># Give it a few seconds to establish<br>sleep 3<br>```<br><br>## Step 6: Test the API<br><br>### Test Health Endpoint<br>```bash<br>curl -s http://localhost:8000/health<br>```<br><br>Expected response:<br>```json<br>{&quot;status&quot;:&quot;healthy&quot;}<br>```<br><br>### Test Chat Completions Endpoint<br>```bash<br>curl -s -X POST http://localhost:8000/v1/chat/completions \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{<br>    &quot;message&quot;: &quot;What is Kubernetes?&quot;,<br>    &quot;max_tokens&quot;: 50,<br>    &quot;temperature&quot;: 0.7<br>  }&#39;<br>```<br><br>Expected response:<br>```json<br>{<br>  &quot;choices&quot;: [<br>    {<br>      &quot;message&quot;: {<br>        &quot;role&quot;: &quot;assistant&quot;,<br>        &quot;content&quot;: &quot; How does it work?\n\nKubernetes (aka K8s) is a platform for deploying, managing and scaling applications on containers...&quot;<br>      }<br>    }<br>  ]<br>}</pre><p>Step 4: Verify KubeRay cluster on kubernetes</p><pre>kubectl port-forward svc/qwen-cpu-serve-head-svc 8265:8265 &gt; /dev/null 2&gt;&amp;1 &amp;<br>open http://127.0.0.1:8265/#/overview</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4sPuJbOE8kOzSLWZ4cnfA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fae129862844" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Data Copilot @scale On Azure]]></title>
            <link>https://medium.com/@bochuxt7/building-data-copilot-scale-on-azure-5b56c4b20743?source=rss-93c4e6649e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b56c4b20743</guid>
            <dc:creator><![CDATA[George Hu]]></dc:creator>
            <pubDate>Sat, 04 May 2024 22:52:36 GMT</pubDate>
            <atom:updated>2024-05-06T17:26:01.551Z</atom:updated>
            <content:encoded><![CDATA[<p>We will building Data Copilot application on Azure.</p><p>Architecture design</p><p>Supported by ChatGPT, we will integrate Microsoft Fabric Onelake to build an enterprise data copilot and deploy production environment on Azure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W8s8PLWZX-Va5T-QdcgiPg.png" /></figure><p><strong>Data Copilot App</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KSMA4EDOlWd09DVYRWgyiA.png" /></figure><p><strong>Deployment</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xAIZjSJr-a6XcsFLqP3PYw.png" /></figure><p><strong>Tech stack:</strong></p><p>1.Taskweaver as AI Agent framework</p><p>2.Azure OpenAI for ChatGPT model deployment</p><p>3.Onelake as enterprise data Lakehouse</p><p>4.Azure Container app as infrastructure</p><p>5.IaC using Azure Bicep</p><p>6.UI using Chainlit</p><p><strong>Customized plugins:</strong></p><p>we need add Onelake loader plugin for Taskweaver AI agent.</p><p><strong>Example:</strong></p><p>Data Copilot as data scientist:</p><p><a href="https://medium.com/@atediarjo/eda-and-regression-analysis-of-boston-housing-dataset-a2d5fe966a5">EDA &amp; Regression Analysis on Boston Housing Price Dataset | by Aryton Tediarjo | Medium</a></p><p>Please load the HousingData.csv from /home/user/app/onelake/ml/HousingData.csv and show the top 5 rows of the loaded data to understand the data schema then create and show graph for the following EDA tasks using above HousingData: Sale Price Distribution Creating More Interesting Temporal Variables Categorical Variables Continuous Variable Relationships Numerical Variables</p><p>ETL demo:</p><h3>load delayed adf job using onelake_loader plugin from /home/user/app/onelake/delayedjob and show first three rows, and apply EDA analysis for the loaded dataset</h3><p>Docker file</p><p>FROM python:3.10-slim</p><p>ARG PORT=8080</p><p>RUN useradd -m -u 1000 user</p><p>USER user</p><p>ENV HOME=/home/user \</p><p>PATH=/home/user/.local/bin:$PATH</p><p>WORKDIR $HOME/app</p><p>COPY — chown=user . $HOME/app</p><p>COPY ./requirements.txt ~/app/requirements.txt</p><p>RUN pip install -r requirements.txt</p><p>EXPOSE $PORT</p><p>COPY . .</p><p>RUN export EXECUTION_SERVICE_KERNEL_MODE=”local”</p><p>RUN export JUPYTER_ALLOW_INSECURE_WRITES=true</p><p>WORKDIR $HOME/app/playground/UI/</p><p>CMD [ “chainlit”, “run”, “app.py”, “ — port”, “8080”]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b56c4b20743" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Copilot-System Design]]></title>
            <link>https://medium.com/@bochuxt7/data-copilot-system-design-df0ae04bcdd2?source=rss-93c4e6649e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/df0ae04bcdd2</guid>
            <dc:creator><![CDATA[George Hu]]></dc:creator>
            <pubDate>Tue, 26 Dec 2023 22:26:58 GMT</pubDate>
            <atom:updated>2023-12-26T23:08:56.243Z</atom:updated>
            <content:encoded><![CDATA[<p>George Hu</p><p>georgehu@microsoft.com</p><p>12/25/2023</p><p><strong>Empower Business Insights with ChatGPT</strong></p><p>This article we will introduce ChatGPT supported agent for big data. We will build a Data Copilot enable intelligence on data lake house for enterprise data like Sales, ERP, Operational, logging and telemetry data etc.</p><p>There are four layers:</p><p>1 Data layer, we will use data lake house for big data persistent</p><p>2 Large language layer, we will adopt ChatGPT 3.5 turbo model</p><p>3 API service layer, we will use flask streaming and restful api</p><p>4 User interface, we will use next js as the web app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0AwLmmsBcTOQsN14Hqhgw.png" /></figure><p>System design</p><p>what is onelake?</p><p>One lake is the default format supported by Microsoft Fabric, the next gen data platform for era of AI. It use open format delta table which was build for internet scale and performance.</p><p>we will use Spark compute engine and Azure ADLS API for onelake connection.</p><p>How to hook dataframe into Large language model?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8swezyBM3aV-JQOmK1gi4A.png" /></figure><p><strong>LLMChain</strong></p><p>we use LLMChain as ChatGPT 3.5 turbo wrapper</p><p><strong>Schema injection</strong></p><p>we use partial prompt property for dataframe schema injection: df.first()</p><p><strong>Data injection</strong></p><p>we use pyspark as dataframe analysis tool, LLM will auto generate pyspark code and execute it on dataframe. We attach dataframe df variable into python locals global variable.</p><p><strong>User interface</strong></p><p>Consider performance, Next JS will be used for building interactive user interface. Flask API will serve as backend API. We use LLM steaming API and flask streaming wrapper to receive request from user.</p><p>Next JS also provide streaming API to communicate with flask streaming API.</p><p><strong>Data Security and Access Control</strong></p><p>We use Microsoft Entra ID as identify for access control, service principle was used for grant user access from Azure Blob account. To reduce LLM content safety, we setup Azure Responsive AI (RAI) service to restriction high level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQ2XChpjNS-wTd7ByAZk6g.png" /></figure><p><strong>Conclusion</strong></p><p>we present the fremework on building ChatGPT driver agent for enterprise data analysis. In the next article, we will show the detailed solution on the challenges we are facing and how we overcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df0ae04bcdd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Airflow 2.5.1 with Spark 3.3.2 integration]]></title>
            <link>https://medium.com/@bochuxt7/airflow-2-5-1-with-spark-3-3-2-integration-5b1746f256c3?source=rss-93c4e6649e10------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b1746f256c3</guid>
            <dc:creator><![CDATA[George Hu]]></dc:creator>
            <pubDate>Tue, 28 Feb 2023 19:48:38 GMT</pubDate>
            <atom:updated>2023-02-28T19:48:38.759Z</atom:updated>
            <content:encoded><![CDATA[<p>Sumit spark job from airflow is tricky. As the default airflow docker image does not have spark operator included. we have to add spark operator using pip install (pip install — no-cache-dir apache-airflow-providers-apache-spark==4.0.0</p><p>).</p><p>Architecture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxUTcrBKJs4xBx9mj-dJcQ.png" /></figure><p><strong>Preparing airflow scheduler docker image</strong></p><p>FROM apache/airflow:2.5.1</p><p>USER root</p><p>RUN sudo apt install wget</p><p>RUN pip install — no-cache-dir apache-airflow-providers-apache-spark==4.0.0</p><p>RUN cd /opt/airflow</p><p>RUN apt-get install vim -y</p><p>RUN wget <a href="https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz">https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz</a> -O openjdk-11+28_linux-x64_bin.tar.gz</p><p>RUN tar -xzf openjdk-11+28_linux-x64_bin.tar.gz</p><p>RUN echo $PATH</p><p>RUN export JAVA_HOME=/opt/airflow/jdk-11</p><p>RUN export PATH=”$PATH:$JAVA_HOME”; echo $PATH</p><p><strong>Preparing docker-compose</strong></p><p>— -</p><p>version: ‘3.4’</p><p>x-common:</p><p>&amp;common</p><p>image: username/airflow251java11:1.0.0</p><p>user: “${AIRFLOW_UID}:0”</p><p># environment:</p><p># — JAVA_HOME=/opt/airflow/jdk-11</p><p>env_file:</p><p>- .env</p><p>volumes:</p><p>- ./dags:/opt/airflow/dags</p><p>- ./logs:/opt/airflow/logs</p><p>- ./plugins:/opt/airflow/plugins</p><p>- /var/run/docker.sock:/var/run/docker.sock</p><p>x-depends-on:</p><p>&amp;depends-on</p><p>depends_on:</p><p>postgres:</p><p>condition: service_healthy</p><p>airflow-init:</p><p>condition: service_completed_successfully</p><p>services:</p><p>postgres:</p><p>image: postgres:13</p><p>container_name: postgres</p><p>ports:</p><p>- “5434:5432”</p><p>healthcheck:</p><p>test: [“CMD”, “pg_isready”, “-U”, “airflow”]</p><p>interval: 5s</p><p>retries: 5</p><p>env_file:</p><p>- .env</p><p>scheduler:</p><p>&lt;&lt;: *common</p><p>&lt;&lt;: *depends-on</p><p>container_name: airflow-scheduler</p><p>command: scheduler</p><p>restart: on-failure</p><p>ports:</p><p>- “8793:8793”</p><p>- “4040:4040”</p><p>webserver:</p><p>&lt;&lt;: *common</p><p>&lt;&lt;: *depends-on</p><p>container_name: airflow-webserver</p><p>restart: always</p><p>command: webserver</p><p>ports:</p><p>- “8080:8080”</p><p>healthcheck:</p><p>test: [“CMD”, “curl”, “ — fail”, &quot;http://localhost:8080/health&quot;]</p><p>interval: 30s</p><p>timeout: 30s</p><p>retries: 5</p><p>airflow-init:</p><p>&lt;&lt;: *common</p><p>container_name: airflow-init</p><p>entrypoint: /bin/bash</p><p>command:</p><p>- -c</p><p>- |</p><p>mkdir -p /sources/logs1 /sources/dags1 /sources/plugins1</p><p>chown -R “${AIRFLOW_UID}:0” /sources/{logs1,dags1,plugins1}</p><p>exec /entrypoint airflow version</p><p><strong>Prepare Dag for Spark job submit</strong></p><p>from __future__ import annotations</p><p>import os</p><p>from datetime import datetime</p><p>from airflow.models import DAG</p><p>from airflow.providers.apache.spark.operators.spark_jdbc import SparkJDBCOperator</p><p>from airflow.providers.apache.spark.operators.spark_sql import SparkSqlOperator</p><p>from airflow.providers.apache.spark.operators.spark_submit import SparkSubmitOperator</p><p>DAG_ID = “example_spark_operator”</p><p>with DAG(</p><p>dag_id=DAG_ID,</p><p>start_date=datetime(2023, 2, 26),</p><p>catchup=False,</p><p>params={</p><p>“master”:”local”,</p><p># Master can be local, yarn, spark://HOST:PORT, mesos://HOST:PORT and</p><p># k8s://https://&lt;HOST&gt;:&lt;PORT&gt;</p><p>“deploy-mode”: “client”</p><p>}</p><p>) as dag:</p><p>submit_job = SparkSubmitOperator(</p><p>application=”/opt/airflow/spark-3.3.2-bin-hadoop3/examples/src/main/python/pi.py”,</p><p>conn_id=’spark_local’,</p><p>task_id=”submit_job1&quot;,</p><p>dag=dag,</p><p># env_vars={‘JAVA_HOME’: ‘/opt/airflow/jdk-11’,’SPARK_HOME’:’/opt/airflow/jdk-11&#39;},</p><p>conf = {</p><p># “spark.yarn.appMasterEnv.JAVA_HOME”:”/opt/airflow/jdk-11&quot;,</p><p>“spark.driver.maxResultSize”: “1g”</p><p>}</p><p>)</p><p>submit_job</p><p><strong>Create connection</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bobfpEynNxkyy0HlXM13Mg.png" /></figure><p><strong>Test and run DAG for sprak job submit</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ceOp9CkFCpKvdPizQmyWqA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b1746f256c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>