Building RAG Pipeline with Chinese AI Models

Jul 27, 2026

title: "Building a RAG Pipeline with Chinese AI Models"

published: true

tags: rag, chinese-ai, langchain, embedding

canonical_url: https://aiwave.live/blog/rag-pipeline-chinese-ai-models

description: "Build a RAG pipeline using Chinese AI models like DeepSeek and GLM. Covers embedding selection, chunking strategies, and a complete Python implementation without LangChain."

RAG (Retrieval-Augmented Generation) combines document retrieval with LLM generation to answer questions grounded in your data. Most RAG tutorials use GPT-4. Chinese AI models work just as well — and cost a fraction of the price.

Available through AIWave with OpenAI-compatible APIs.

Architecture

Documents → Chunking → Embedding → Vector Store → Query Embedding → Similarity Search → LLM → Answer

Embedding Model Selection

For Chinese text, embedding model choice matters:

ModelDimensionsChineseCostSource
text-embedding-3-small1536OK$0.02/1M tokensOpenAI
bge-m31024ExcellentFree (local)BAAI
bge-large-zh-v1.51024ExcellentFree (local)BAAI

For Chinese-heavy content, BGE models (from BAAI) outperform OpenAI's embeddings. bge-m3 supports multilingual text and is small enough to run locally.

Chunking Strategy

Chinese text chunking differs from English:

  • No word-level tokenization: Chinese doesn't have spaces between words. Chunk by character count (500-1000 chars) rather than word count
  • Paragraph boundaries: Prefer splitting at paragraph breaks (\n\n) to maintain semantic coherence
  • Overlap: 100-200 character overlap between chunks to avoid losing context at boundaries
  • def chunk_text(text, chunk_size=800, overlap=200):
        chunks = []
        start = 0
        while start < len(text):
            end = start + chunk_size
            chunks.append(text[start:end])
            start = end - overlap
        return chunks

    Vector Store

    Use FAISS (local, free) or a hosted solution:

    import faiss
    import numpy as np
    from openai import OpenAI
    
    client = OpenAI(api_key="***", base_url="https://aiwave.live/v1")
    
    embeddings = []
    for chunk in chunks:
        resp = client.embeddings.create(
            model="text-embedding-3-small",
            input=chunk
        )
        embeddings.append(resp.data[0].embedding)
    
    index = faiss.IndexFlatIP(len(embeddings[0]))
    index.add(np.array(embeddings).astype('float32'))

    Query and Generation

    def query_rag(question, index, chunks, top_k=3):
        resp = client.embeddings.create(
            model="text-embedding-3-small",
            input=question
        )
        query_vec = np.array([resp.data[0].embedding]).astype('float32')
        distances, indices = index.search(query_vec, top_k)
        context = "\n\n".join([chunks[i] for i in indices[0]])
        
        response = client.chat.completions.create(
            model="deepseek-chat",
            messages=[
                {"role": "system", "content": "Answer based on the provided context."},
                {"role": "user", "content": f"Context:\n{context}\n\nQuestion: {question}"}
            ]
        )
        return response.choices[0].message.content

    Cost

    Using DeepSeek V4 Flash ($0.14/$0.28) for generation and text-embedding-3-small for retrieval:

  • 100 documents × 10 chunks × 1536-dim embedding: ~$0.01
  • 1,000 RAG queries × 4K context average: ~$5/month
  • Compare to GPT-4o: ~$60/month for the same workload.

    All components are available through AIWave with a single API key. The $1 free credit covers your first 5,000+ RAG queries. Replace LangChain with 100 lines of standard Python — simpler, faster, no framework lock-in.