หน้าแรก / คู่มือ / LLM ฟรีสำหรับ LlamaIndex

LLM ฟรีสำหรับ LlamaIndex

LlamaIndex มีสองคลาสสำหรับ API ที่เข้ากันได้กับ OpenAI: OpenAILike สำหรับแชต และ OpenAILikeEmbedding สำหรับ embeddings คู่มือนี้ชี้ทั้งสองไปยัง FreeLLMAPI ซึ่งรวมระดับฟรีของผู้ให้บริการ 45 ราย ไว้หลังคีย์เดียว คุณสร้างดัชนี retrieval-augmented generation (RAG) ค้นหาจากดัชนีนั้น และเพิ่มเอเจนต์ โค้ดจัดการขีดจำกัดอัตรา

โค้ด ชื่อโมเดล และป้ายกำกับของแคตตาล็อกสดจะแสดงเป็นภาษาอังกฤษ

ติดตั้งแพ็กเกจ

ติดตั้ง FreeLLMAPI และเพิ่มคีย์ฟรีจากผู้ให้บริการสองรายขึ้นไปในหน้า Keys ของแดชบอร์ด คัดลอก unified key จากนั้นติดตั้งแพ็กเกจ LlamaIndex

ติดตั้ง

curl -fsSL https://freellmapi.co/install.sh | bash

pip install -U llama-index-core \
  llama-index-llms-openai-like \
  llama-index-embeddings-openai-like

export FREELLMAPI_BASE_URL=http://localhost:3001/v1
export FREELLMAPI_API_KEY=<unified-key>

อย่าใช้คลาส OpenAI ธรรมดาจาก llama-index-llms-openai กับชื่อโมเดลที่ OpenAI ไม่รู้จัก คลาสนั้นตรวจชื่อโมเดลและขนาดบริบทกับรายการโมเดลของ OpenAI OpenAILike ไม่ตรวจ ดังนั้นคุณกำหนดค่าเหล่านี้เอง

ตั้งค่า LLM และโมเดล embedding

settings.py

import os
from llama_index.core import Settings
from llama_index.llms.openai_like import OpenAILike
from llama_index.embeddings.openai_like import OpenAILikeEmbedding

BASE = os.environ["FREELLMAPI_BASE_URL"]
KEY = os.environ["FREELLMAPI_API_KEY"]

Settings.llm = OpenAILike(
    model="auto",
    api_base=BASE,
    api_key=KEY,
    is_chat_model=True,              # use /v1/chat/completions
    is_function_calling_model=True,  # needed for FunctionAgent
    context_window=32000,            # the smallest window in your chain
    max_retries=5,
    timeout=90,
)

Settings.embed_model = OpenAILikeEmbedding(
    model_name="bge-m3",  # one family, 1024 dimensions
    api_base=BASE,
    api_key=KEY,
    embed_batch_size=16,
    max_retries=10,
)
  • is_chat_model=True: หากไม่มีค่านี้ LlamaIndex จะส่งคำขอไปยัง endpoint การเติมข้อความรุ่นเดิม
  • context_window: LlamaIndex ใช้ค่านี้เพื่อตัดสินว่าชิ้นข้อมูลที่ดึงมาได้กี่ชิ้นจะพอดีกับพรอมต์ ด้วย auto เราเตอร์อาจเลือกโมเดลต่างกัน ใช้หน้าต่างบริบทที่เล็กที่สุดในลำดับของคุณ
  • is_function_calling_model=True: ตั้งค่านี้เฉพาะเมื่อลำดับของคุณมีโมเดลที่รองรับ tool calling
  • embed_batch_size: แต่ละชุดคือหนึ่งคำขอ ชุดที่ใหญ่กว่าใช้คำขอต่อนาทีน้อยกว่า

พรอมต์ RAG บรรจุชิ้นข้อมูลที่ดึงมาหลายชิ้น ดังนั้นโมเดลแชตต้องมีพื้นที่สำหรับชิ้นเหล่านั้น สร้างโปรไฟล์ลำดับ fallback ที่มีโมเดลบริบทยาวสำหรับ RAG แล้วตั้ง model="auto:<profile>" และเพิ่ม context_window ให้เท่ากับหน้าต่างที่เล็กที่สุดในโปรไฟล์นั้น โมเดลฟรีเหล่านี้มีหน้าต่างบริบทใหญ่ที่สุดในวันนี้:

โมเดลฟรีที่มีหน้าต่างบริบทใหญ่ที่สุด
โมเดลฟรีบนขนาดบริบทขีดจำกัดฟรี (ข้อเสนอที่ดีที่สุด)เครื่องมือการอ่านภาพ
OpenAI: GPT-6 LunaElectronHub1.1M$0.25/week shared free creditsไม่ไม่
Gemini 3.8 FlashAPINex, Google AI Studio1M5 คำขอ/นาที
10M weighted tokens/day shared across APINex free routes; 3x token multiplier; 5 requests/minute/account
ใช่ใช่
Gemini 3.7 FlashGoogle AI Studio1M10 คำขอ/นาที
20 คำขอ/วัน
250,000 โทเคน/นาที
~3M
ใช่ใช่
DeepSeek V4 FlashAMD Radeon Cloud, BazaarLink, ElectronHub1M10 คำขอ/นาที
50 คำขอ/วัน
Shared rate limit
ใช่ไม่
DeepSeek V4 Flash 0731ElectronHub, Router91M10,000 credits/month (~$1), shared; account-anniversary resetไม่ไม่
Gemini 3.6 FlashGoogle AI Studio1M10 คำขอ/นาที
20 คำขอ/วัน
250,000 โทเคน/นาที
~3M
ใช่ใช่
GLM-5.2ModelScope, Router91M100 คำขอ/วัน
Daily login: 200 credits + 50 for linked Alibaba Cloud; 24h expiry; shared; noncommercial experience
ไม่ไม่
Gemini 3.5 FlashGoogle AI Studio1M10 คำขอ/นาที
20 คำขอ/วัน
250,000 โทเคน/นาที
~3M
ใช่ใช่

แสดง 8 จาก 115 โมเดลฟรีที่ตรงกัน ดูโมเดลทั้งหมด.

ข้อมูลสดจากแคตตาล็อก FreeLLMAPI (เวอร์ชัน 2026.11.19 ตรวจสอบเมื่อ 2026-11-19) ขีดจำกัดฟรีเปลี่ยนบ่อย แคตตาล็อกถูกตรวจสอบทุกวัน

หากต้องการให้ผู้ใช้หนึ่งคนอยู่บนโมเดลเดียว ส่งส่วนหัว X-Session-Id OpenAILike รับ default_headers เช่น default_headers={"X-Session-Id": "user-42"} FreeLLMAPI เก็บเซสชันไว้บนโมเดลเดียวเป็นเวลา 30 นาที ซึ่งให้คำตอบที่สไตล์เดียวกันตลอดหนึ่งแชต

สร้างและค้นหาดัชนี RAG

สคริปต์อ่านไฟล์จากโฟลเดอร์ สร้าง embeddings บันทึกดัชนี และตอบคำถาม รันครั้งแรกเพื่อสร้างดัชนี การรันครั้งต่อไปโหลดดัชนีที่บันทึกไว้และไม่ embed ไฟล์เดิมซ้ำ

rag.py

import os
import settings  # noqa: F401  (sets Settings.llm and Settings.embed_model)
from llama_index.core import (
    SimpleDirectoryReader,
    StorageContext,
    VectorStoreIndex,
    load_index_from_storage,
)

PERSIST = "./storage"


def load_index() -> VectorStoreIndex:
    if os.path.isdir(PERSIST):
        return load_index_from_storage(StorageContext.from_defaults(persist_dir=PERSIST))
    docs = SimpleDirectoryReader("./docs").load_data()
    index = VectorStoreIndex.from_documents(docs, show_progress=True)
    index.storage_context.persist(persist_dir=PERSIST)
    return index


if __name__ == "__main__":
    query_engine = load_index().as_query_engine(similarity_top_k=4, streaming=True)
    response = query_engine.query("How do I rotate the API keys?")
    response.print_response_stream()
    for node in response.source_nodes:
        print("\nSource:", node.metadata.get("file_name"), round(node.score or 0, 3))
สำคัญ: ใช้ embedding family เดียวสำหรับดัชนีทั้งหมด FreeLLMAPI ไม่เปลี่ยนโมเดล embedding ระหว่าง failover มันย้ายได้เฉพาะระหว่างผู้ให้บริการที่ให้ family เดียวกัน หากคุณเปลี่ยน family ให้ลบ ./storage แล้วสร้างดัชนีใหม่

โมเดล embedding เหล่านี้ฟรีในแคตตาล็อกวันนี้ คอลัมน์ dimensions แสดงขนาดเวกเตอร์ของแต่ละ family

โมเดลผู้ให้บริการมิติอินพุตสูงสุดขีดจำกัดฟรี
Gemini Embedding
gemini-embedding-001
Google AI Studio30722048100 rpm · 1K req/day
Nemotron Embed VL 1B
nvidia/llama-nemotron-embed-vl-1b-v2
NVIDIA NIM20488192~40 rpm
Nemotron 3 Embed 1B (OR free)
nvidia/nemotron-3-embed-1b:free
OpenRouter20483276820 rpm · shared free daily cap
SEA-LION E5 Embedding 600M
aisingapore/SEA-LION-E5-Embedding-600M
SEA-LION10248192free · 10 rpm
SEA-LION ModernBERT Embedding 300M
aisingapore/SEA-LION-ModernBERT-Embedding-300M
SEA-LION10248192free · 10 rpm
SEA-LION ModernBERT Embedding 600M
aisingapore/SEA-LION-ModernBERT-Embedding-600M
SEA-LION10248192free · 10 rpm
BGE-M3
@cf/baai/bge-m3
Cloudflare Workers AI1024819210K neurons/day (shared)
EmbeddingGemma 300M
@cf/google/embeddinggemma-300m
Cloudflare Workers AI768204810K neurons/day (shared)
Qwen3 Embedding 0.6B
@cf/qwen/qwen3-embedding-0.6b
Cloudflare Workers AI1024819210K neurons/day (shared)
Cohere Embed v4
embed-v4.0
Cohere15361280001K calls/mo (shared w/ chat)
Gemini Embedding 2
gemini-embedding-2
Google AI Studio30728192free-tier rate limited
Nemotron 3 Embed 1B
nvidia/nemotron-3-embed-1b
NVIDIA NIM20484096~40 rpm
PLaMo Embedding 1B (CF)
@cf/pfnet/plamo-embedding-1b
Cloudflare Workers AI2048409610K neurons/day (shared)
BGE Small EN v1.5 (CF)
@cf/baai/bge-small-en-v1.5
Cloudflare Workers AI38451210K neurons/day (shared)
BGE Base EN v1.5 (CF)
@cf/baai/bge-base-en-v1.5
Cloudflare Workers AI76851210K neurons/day (shared)
BGE Large EN v1.5 (CF)
@cf/baai/bge-large-en-v1.5
Cloudflare Workers AI102451210K neurons/day (shared)
Mistral Embed
mistral-embed
Mistral10248192free mode · monthly cap (shared)
Codestral Embed
codestral-embed
Mistral15368192free mode · monthly cap (shared)
Llama Text Embed v2 (Pinecone)
llama-text-embed-v2
Pinecone102420485M tokens/mo per model
Multilingual E5 Large (Pinecone)
multilingual-e5-large
Pinecone10245075M tokens/mo per model
Nemotron 3 Embed 1B (Speka)
nvidia/nemotron-3-embed-1b
Speka20488192$1/month shared across Speka models
OpenAI: Text Embedding 3 Small (ElectronHub)
text-embedding-3-small
ElectronHub15368192$0.25/week shared free credits
OpenAI: Text Embedding 3 Large (ElectronHub)
text-embedding-3-large
ElectronHub30728192$0.25/week shared free credits
Nemotron 3 Embed 8B (Inferbase)
nvidia-nemotron-3-embed-8b
Inferbase409681925,000 requests/month; 100 requests and $0.50 usage/day shared
Qwen 3 Embedding 0.6B (Inferbase)
qwen3-embedding-0-6b
Inferbase102481925,000 requests/month; 100 requests and $0.50 usage/day shared
Qwen 3 Embedding 4B (Inferbase)
qwen3-embedding-4b
Inferbase256081925,000 requests/month; 100 requests and $0.50 usage/day shared
Qwen 3 Embedding 8B (Inferbase)
qwen3-embedding-8b
Inferbase409681925,000 requests/month; 100 requests and $0.50 usage/day shared
LFM2.5 Embedding 350M (LLMTR)
liquid/lfm-2.5-embedding-350m-free
LLMTR1024512Ongoing zero-price route; provider terms apply
BGE-M3 (SEA-LION)
BAAI/bge-m3
SEA-LION10248192free · 10 rpm
Cohere Embed English v3
embed-english-v3.0
Cohere10245121K calls/mo (shared w/ chat)
Qwen3 Embedding 8B (OVH)
Qwen3-Embedding-8B
OVH AI Endpoints409632768free · anonymous 2 req/min per IP
BGE-M3 (OVH)
bge-m3
OVH AI Endpoints10248192free · anonymous 2 req/min per IP
BGE Multilingual Gemma2 (OVH)
bge-multilingual-gemma2
OVH AI Endpoints35848192free · anonymous 2 req/min per IP
Mistral: Codestral Embed (ElectronHub)
codestral-embed
ElectronHub15368192$0.25/week shared free credits
Mistral: Mistral Embed (ElectronHub)
mistral-embed
ElectronHub10248192$0.25/week shared free credits
Google: Gemini Embedding 2 (ElectronHub)
gemini-embedding-2
ElectronHub30728192$0.25/week shared free credits
Google: Gemini Embedding 001 (ElectronHub)
gemini-embedding-001
ElectronHub30722048$0.25/week shared free credits
OpenAI: Text Embedding Ada 002 (ElectronHub)
text-embedding-ada-002
ElectronHub15368192$0.25/week shared free credits
Cohere Embed English Light v3
embed-english-light-v3.0
Cohere3845121K calls/mo (shared w/ chat)
Cohere Embed Multilingual v3
embed-multilingual-v3.0
Cohere10245121K calls/mo (shared w/ chat)
Cohere Embed Multilingual Light v3
embed-multilingual-light-v3.0
Cohere3845121K calls/mo (shared w/ chat)

ข้อมูลสดจากแคตตาล็อก FreeLLMAPI (เวอร์ชัน 2026.11.19 ตรวจสอบเมื่อ 2026-11-19) ขีดจำกัดฟรีเปลี่ยนบ่อย แคตตาล็อกถูกตรวจสอบทุกวัน

เพิ่มเอเจนต์ด้วย FunctionAgent

FunctionAgent ใช้ tool calling คุณให้ query engine เป็นเครื่องมือได้ และเพิ่มฟังก์ชัน Python ของคุณเองได้

agent.py

import asyncio
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.tools import QueryEngineTool
from llama_index.core import Settings
from rag import load_index

docs_tool = QueryEngineTool.from_defaults(
    query_engine=load_index().as_query_engine(similarity_top_k=4),
    name="project_docs",
    description="Answers questions about the project documentation.",
)

def open_tickets(team: str) -> int:
    """Return the number of open tickets for a team."""
    return {"billing": 4, "platform": 11}.get(team, 0)

agent = FunctionAgent(
    tools=[docs_tool, open_tickets],
    llm=Settings.llm,
    system_prompt="Use the tools. Cite the document name in each answer.",
)

async def main():
    result = await agent.run("How many platform tickets are open, and how do we rotate keys?")
    print(result)

asyncio.run(main())

สำหรับงานเอเจนต์ เลือกโมเดลที่รองรับ tool calling สร้างโปรไฟล์ลำดับ fallback ที่มีเฉพาะโมเดลเหล่านี้ แล้วใช้ auto:<profile> เป็นชื่อโมเดล

โมเดลฟรีที่รองรับ tool calling และบริบท 128K ขึ้นไป
โมเดลฟรีบนขนาดบริบทขีดจำกัดฟรี (ข้อเสนอที่ดีที่สุด)เครื่องมือการอ่านภาพ
GLM 5.3UnoRouter1M1 คำขอ/นาที
1 req/min per model
ใช่ไม่
GLM 5.3 FlashNVIDIA NIM, UnoRouter1M40 คำขอ/นาที
40 RPM
ใช่ใช่
Gemini 3.8 FlashGoogle AI Studio1MRecurring provider quotaใช่ใช่
Qwen3.8 Flash NextAMD Radeon Cloud262KRecurring daily account allowanceใช่ไม่
Qwen3.8 FlashElectronHub1M$0.25/week shared recurring creditใช่ใช่
Gemini 3.7 FlashGoogle AI Studio1M10 คำขอ/นาที
20 คำขอ/วัน
250,000 โทเคน/นาที
~3M
ใช่ใช่
GPT-5.6 LunaElectronHub1M$0.25/week shared recurring creditใช่ใช่
Dots3 Note PreviewKilo Gateway, OpenRouter512K20 คำขอ/นาที
50 คำขอ/วัน
50 req/day account-wide (1,000 after a $10 purchase)
ใช่ใช่
DeepSeek V4 FlashAMD Radeon Cloud, BazaarLink, ElectronHub1M10 คำขอ/นาที
50 คำขอ/วัน
Shared rate limit
ใช่ไม่
Qwen3.8 27BElectronHub, Groq, OVH AI Endpoints262K30 คำขอ/นาที
250 คำขอ/วัน
70,000 โทเคน/นาที
~6M
ใช่ใช่

แสดง 10 จาก 109 โมเดลฟรีที่ตรงกัน ดูโมเดลทั้งหมด.

ข้อมูลสดจากแคตตาล็อก FreeLLMAPI (เวอร์ชัน 2026.11.19 ตรวจสอบเมื่อ 2026-11-19) ขีดจำกัดฟรีเปลี่ยนบ่อย แคตตาล็อกถูกตรวจสอบทุกวัน

ให้การนำเข้าข้อมูลอยู่ในขีดจำกัดฟรี

การนำเข้าข้อมูลส่งคำขอ embedding จำนวนมากในเวลาอันสั้น ระดับ embedding ฟรีมีขีดจำกัดต่ำ เช่น บางรายอนุญาต 10 คำขอต่อนาที และบางรายนับการเรียกต่อเดือน วางแผนการนำเข้าครั้งแรกก่อนเริ่ม

  • ใช้ชิ้นข้อมูลขนาดใหญ่ ชิ้นข้อมูลน้อยลงหมายถึงเวกเตอร์และคำขอน้อยลง ขนาดชิ้นใกล้ 1,024 โทเคนเป็นจุดเริ่มต้นที่ดี
  • ใช้ชุด (batch) ตั้ง embed_batch_size เป็น 16 ขึ้นไป แล้วหนึ่งคำขอจะบรรจุชิ้นข้อมูลจำนวนมาก
  • บันทึกดัชนี เก็บดัชนีไว้หลังการรันครั้งแรก อย่า embed ไฟล์เดิมซ้ำ
  • เปิดการลองใหม่ OpenAILikeEmbedding ลองใหม่สูงสุด 10 ครั้งตามค่าเริ่มต้น เก็บค่านี้ไว้สำหรับงานนำเข้าที่ยาว
  • นำเข้าเป็นส่วน ๆ สำหรับหลักพันไฟล์ ให้นำเข้าทีละโฟลเดอร์

การค้นหาถูกกว่าการนำเข้า การค้นหาแต่ละครั้งใช้หนึ่งคำขอ embedding และหนึ่งคำขอแชต คำขอแชตที่มีสี่ชิ้นข้อมูลขนาด 1,024 โทเคนส่งประมาณ 5,000 โทเคน ระดับฟรีที่มีขีดจำกัดโทเคนต่อนาทีต่ำอาจปฏิเสธคำขอนี้ จากนั้น FreeLLMAPI ลองผู้ให้บริการรายถัดไป

การแก้ปัญหา

ปัญหาสาเหตุวิธีแก้
Unknown model 'auto'คุณใช้คลาส OpenAIใช้ OpenAILike
คำขอไปยัง /v1/completionsไม่ได้ตั้ง is_chat_modelตั้ง is_chat_model=True
เอเจนต์ไม่เรียกเครื่องมือis_function_calling_model ปิดอยู่ หรือโมเดลไม่รองรับ tool callingตั้งเป็น True และใช้โปรไฟล์สำหรับเครื่องมือ
ข้อผิดพลาด 429 ระหว่างการนำเข้าembedding family ถึงขีดจำกัดในทุกผู้ให้บริการใช้ชุดที่ใหญ่ขึ้น รอตาม Retry-After แล้วรันอีกครั้ง
คำตอบไม่ดีหลังเปลี่ยนโมเดล embeddingมีเวกเตอร์จากสอง family ในดัชนีเดียวลบดัชนีที่บันทึกไว้และสร้างใหม่
ข้อผิดพลาดความยาวบริบทcontext_window ใหญ่กว่าโมเดลที่ตอบตั้งค่าที่เล็กลง หรือใช้โปรไฟล์บริบทยาว

หากต้องการดูว่าผู้ให้บริการรายใดตอบคำขอ ใช้แดชบอร์ดของ FreeLLMAPI หน้า Analytics แสดงคำขอ ความหน่วง และข้อผิดพลาดของแต่ละผู้ให้บริการและโมเดล การตอบกลับแต่ละครั้งยังมีส่วนหัว X-Routed-Via หากเราเตอร์เปลี่ยนผู้ให้บริการ ส่วนหัว X-Fallback-Trail จะระบุแต่ละความพยายามที่ล้มเหลวและเหตุผล

ใช้ทุกตัวในรายการนี้ผ่านคีย์เดียว FreeLLMAPI คือเราเตอร์โอเพนซอร์สที่คุณโฮสต์เอง รวมระดับฟรีทั้งหมดนี้ไว้หลังปลายทางเดียวที่เข้ากันได้กับ OpenAI และเปลี่ยนไปใช้ตัวอื่นเมื่อตัวใดตัวหนึ่งถูกจำกัดอัตรา ดูแคตตาล็อก หรือ เริ่มใช้งานจริง.

คำถามที่พบบ่อย

ฉันใช้ LlamaIndex กับ LLM ฟรีได้หรือไม่

ได้ ใช้ OpenAILike โดยตั้ง api_base เป็น URL ที่เข้ากันได้กับ OpenAI FreeLLMAPI ให้ URL เดียวสำหรับระดับฟรีของผู้ให้บริการหลายราย แต่ละระดับมีขีดจำกัดของตัวเอง

OpenAI กับ OpenAILike ใน LlamaIndex ต่างกันอย่างไร

คลาส OpenAI ตรวจชื่อโมเดลกับโมเดลของ OpenAI ส่วน OpenAILike รับชื่อโมเดลใดก็ได้ คุณกำหนดหน้าต่างบริบทและตัวบ่งชี้แชตกับ function calling เอง

โมเดล embedding ฟรีตัวไหนดีที่สุดสำหรับ LlamaIndex

เลือก family ที่มีคำขอฟรีเพียงพอสำหรับการนำเข้าของคุณ และใช้ family นั้นตลอดทั้งดัชนี family bge-m3 ฟรีในหลายผู้ให้บริการ failover จึงย้ายระหว่างกันได้

FunctionAgent ใช้กับโมเดลฟรีได้หรือไม่

ได้ หากโมเดลรองรับ tool calling และคุณตั้ง is_function_calling_model=True ใช้โปรไฟล์ลำดับ fallback ที่มีเฉพาะโมเดลที่รองรับ tool calling

ฉันจะหลีกเลี่ยงขีดจำกัดอัตราเมื่อสร้างดัชนี LlamaIndex ได้อย่างไร

ใช้ชิ้นข้อมูลขนาดใหญ่ ตั้ง embed_batch_size เป็น 16 ขึ้นไป บันทึกดัชนี และนำเข้าโฟลเดอร์ขนาดใหญ่เป็นส่วน ๆ

คู่มือที่เกี่ยวข้อง

แหล่งข้อมูล

คู่มือทั้งหมด · ดูโมเดลฟรีทั้งหมด