Skip to content

Build a LlamaIndex RAG app on SynapCores: SQL vector search and a local LLM

LlamaIndex splits your documents into chunks and runs the query engine. SynapCores stores the chunks, embeds and ranks them in SQL, and serves the chat model that writes the answer, so the whole RAG pipeline runs on one engine with one login.

Tested on SynapCores 2.5.0-ceUpdated November 18, 2026

Install free, one command

curl -fsSL https://get.synapcores.com | SYNAPCORES_REF=docs-llamaindex sh

Free Community Edition. Linux (x86_64, aarch64) and macOS on Apple Silicon; Windows via WSL2. Docker and other options

You need a running engine (quickstart or Docker), its admin password, Python 3.11 or later, and a chat model on the engine. GET /api/tags lists the models your engine serves.

Install the packages

bash
python3 -m venv venv
source venv/bin/activate
pip install llama-index-core llama-index-llms-ollama synapcores

llama-index-core brings documents, the sentence splitter and the query engine, llama-index-llms-ollama connects LlamaIndex to the chat model on your engine, and synapcores is the Python SDK. This guide was tested with llama-index-core 0.14.26, llama-index-llms-ollama 0.12.0 and synapcores 0.5.0.

Build the RAG pipeline

Save this as rag.py and set CHAT_MODEL to a chat model from your engine. The script stores four short help articles, retrieves the ones closest in meaning to a question, and has the model answer from them:

rag.py
import os

from llama_index.core import Document
from llama_index.core.node_parser import SentenceSplitter
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.core.retrievers import BaseRetriever
from llama_index.core.schema import NodeWithScore, TextNode
from llama_index.llms.ollama import Ollama
from synapcores import SynapCores

CHAT_MODEL = "qwen2.5-coder:7b"  # any chat model from GET /api/tags on your engine

db = SynapCores(host="localhost", port=8080)
db.login(os.environ["SYNAPCORES_USER"], os.environ["SYNAPCORES_PASSWORD"])

# 1. Chunk documents with LlamaIndex and store the chunks in SynapCores.
#    EMBED() computes each vector inside the database with the local all-MiniLM model.
db.sql("CREATE DATABASE IF NOT EXISTS li_demo")
db.sql("""CREATE TABLE IF NOT EXISTS li_demo.chunks (
    id INTEGER PRIMARY KEY, topic TEXT, body TEXT, embedding VECTOR(384))""")

docs = [Document(text=t, metadata={"topic": k}) for k, t in [
    ("billing", "Refunds: you can request a full refund within 14 days of purchase from Billing > Invoices > Request refund."),
    ("account", "Password reset: open Settings > Security and click 'Send reset link'. The link expires after 30 minutes."),
    ("team", "Invite a teammate from Workspace > Members by entering their email address. Invites expire after 7 days."),
    ("security", "Two-factor authentication is enabled under Settings > Security > 2FA with any TOTP authenticator app."),
]]
nodes = SentenceSplitter(chunk_size=256).get_nodes_from_documents(docs)
for i, node in enumerate(nodes, 1):
    db.sql("INSERT INTO li_demo.chunks VALUES ($1, $2, $3, EMBED($3))",
           [i, node.metadata["topic"], node.get_content()])


# 2. A LlamaIndex retriever that ranks chunks by meaning in SQL.
class SynapCoresRetriever(BaseRetriever):
    def _retrieve(self, query_bundle):
        rows = db.sql("""SELECT topic, body, COSINE_SIMILARITY(embedding, EMBED($1)) AS score
            FROM li_demo.chunks ORDER BY score DESC LIMIT 2""", [query_bundle.query_str])
        return [NodeWithScore(node=TextNode(text=r.body, metadata={"topic": r.topic}), score=r.score)
                for r in rows.itertuples()]


# 3. Answer with a chat model served by the same engine (Ollama-compatible API, same login).
llm = Ollama(
    model=CHAT_MODEL,
    base_url="http://localhost:8080",
    headers={"Authorization": f"Bearer {db.jwt_token}"},
    context_window=8192,
    request_timeout=120,
)
retriever = SynapCoresRetriever()

for hit in retriever.retrieve("How do I get my money back?"):
    print(f"{hit.score:.3f}  [{hit.node.metadata['topic']}] {hit.node.get_content()[:60]}...")

query_engine = RetrieverQueryEngine.from_args(retriever, llm=llm)
print(query_engine.query("How many days do I have to ask for a refund?"))

db.sql("DROP DATABASE li_demo")
db.close()
bash
export SYNAPCORES_USER=admin
export SYNAPCORES_PASSWORD='your-admin-password'
python rag.py
Output
0.472  [billing] Refunds: you can request a full refund within 14 days of pur...
0.207  [account] Password reset: open Settings > Security and click 'Send res...
You can request a full refund within 14 days of purchase.

The first two lines are what the retriever finds for "How do I get my money back?": the refund policy ranks first, although it shares no keywords with the question. The last line is the model's answer to "How many days do I have to ask for a refund?", written from the retrieved chunk. The script drops its database at the end, so you can run it again.

How it works

  • SentenceSplitter splits each LlamaIndex Document into chunks of up to 256 tokens, keeping sentences together, and copies the document's metadata (here the topic) onto every chunk.
  • EMBED($3) computes a 384-dimension embedding for each chunk inside the database, with the local all-MiniLM model, as the row is inserted. Your Python code never handles vectors.
  • SynapCoresRetriever is a LlamaIndex BaseRetriever. Its _retrieve() runs one SQL query: EMBED($1) embeds the question and COSINE_SIMILARITY() ranks the stored chunks. It returns NodeWithScore objects, so RetrieverQueryEngine uses it like a built-in retriever.
  • Ollama from llama-index-llms-ollama calls the chat model your engine serves through its Ollama-compatible API. base_url points it at the engine, headers carries the session token from db.login(), and context_window sets the context size the model runs with.
  • RetrieverQueryEngine puts the retrieved chunks into the prompt and returns the model's answer.

Connect with an API key

For services and scripts that run unattended, use an API key instead of a password (the MCP guide shows how to create one). In rag.py, replace the two lines that create db and log in with the first statement below, and send the same key to the chat model:

rag.py
db = SynapCores(host="localhost", port=8080, api_key=os.environ["SYNAPCORES_API_KEY"])

llm = Ollama(
    model=CHAT_MODEL,
    base_url="http://localhost:8080",
    headers={"Authorization": f"Bearer {os.environ['SYNAPCORES_API_KEY']}"},
    context_window=8192,
    request_timeout=120,
)
bash
export SYNAPCORES_API_KEY='your-api-key'
python rag.py

The script prints the same output as above.

Go further

  • To index your own content, build docs from your own text and keep the fields you want to show with each hit, such as a title or a source URL, as metadata and table columns.
  • EMBED(), VECTOR and COSINE_SIMILARITY() are in the SQL reference, with every other function the engine runs.
  • Call the same chat and embedding models directly with curl or the official ollama client: see the Ollama-compatible API guide.

Next steps

Full reference

  • SQL reference: Every statement and function: EMBED, VECTOR, COSINE_SIMILARITY, GENERATE, Cypher, AutoML, agent memory.
  • API reference: The REST API. Your engine also serves its own OpenAPI schema at /v1/openapi.json.
  • System requirements: Supported platforms, memory and disk sizing.