xb

AI Application Starter (English)

This page consolidates guidance that used to live under xb/doc/ai_application/. It focuses on three workflows: Retrieval-Augmented Generation (RAG), Agent tooling, and analytics dashboards backed by xb.


1. Retrieval-Augmented Generation (RAG)

1.1 Data pipeline checklist

  1. Chunking – split documents into 512-1024 token windows.
  2. Embedding – store the raw vector, the text, and metadata (tenant_id, lang, tags).
  3. Indexing – choose a Qdrant collection per tenant or per domain.
  4. Sync metadata – keep SQL + vector stores in lockstep via CDC or async jobs.

1.2 Query pipeline

queryVec := embedder.Encode(prompt)

resultsJSON, _ := xb.Of(&DocVector{}).
    Custom(qdrantCustom).
    Eq("tenant_id", tenantID).
    VectorSearch("embedding", queryVec, 8).
    Build().
    JsonOfSelect()

Feed resultsJSON to the RAG orchestrator (LangChain, LlamaIndex, Semantic Kernel, etc.). Each toolkit consumes the same payload because xb sticks to raw Qdrant JSON.


2. Agent tooling

Example tool definition:

func RecommendFeedTool(input RecommendInput) (string, error) {
    json, err := xb.Of(&FeedVector{}).
        Custom(qdrantCustom).
        Eq("tenant_id", input.Tenant).
        VectorSearch("embedding", input.Vector, input.Limit).
        Build().
        JsonOfSelect()
    if err != nil {
        return "", err
    }
    return string(json), nil
}

3. Analytics dashboards

Even if the front-end is SQL-only, xb helps keep AI activity auditable:


4. Integration notes

Toolkit Tip
LangChain Wrap xb builders as Runnable objects; use JsonOfSelect output directly
LlamaIndex Register a custom retriever that calls xb; keep metadata consistent
Semantic Kernel Implement IQueryFunction to invoke xb and return embeddings

5. Where to go next

If you have a repeatable AI workflow (RAG, agent, analytics) worth sharing, PRs to this file are welcome.