Whatever message this page gives is out now! Go check it out!

SimpleRAG

Last update:
May 18, 2026
Creates and returns a SimpleRAGService instance that provides zero-configuration Retrieval-Augmented Generation (RAG) for ColdFusion applications. With only two mandatory parameters, developers can build powerful AI-powered document Q&A systems.

Syntax

SimpleRAG(
    source,    // Required — String or Array
    model,     // Required — CF ChatModel or Struct
    options    // Optional — Struct
)

Parameters

Parameter
Type
Required
Description
source
String / Array
Required
A local file path (e.g., "./docs/manual.pdf"), a local directory path (e.g., "./docs/") that is recursively scanned, a URL (e.g., "https://example.com/guide.html"), or an array of any combination of the above.
model
CF ChatModel / Struct
Required
A CF ChatModel object returned by ChatModel(), or a Struct with at minimum provider and credential keys.
options
Struct
Optional
Configuration overrides. See the Options Struct Keys table below. Omitting this parameter uses intelligent defaults suitable for most use cases.

Options struct keys

Key
Type
Default
Description
chunkSize
Numeric
1000
Maximum character count per document chunk.
chunkOverlap
Numeric
200
Overlapping characters between consecutive chunks to preserve context.
splitterType
String
"recursive"
Splitting strategy: "recursive", "paragraph", "sentence", "line", "character", "word", "regex". When splitterType = "regex", the regexPattern key is required; omitting it throws an "Invalid document splitter configuration" validation error.
maxResults
Numeric
5
Maximum document chunks retrieved per query.
minScore
Numeric
0.7
Minimum similarity score (0.0–1.0) for retrieved chunks.
vectorStore
VectorStore
In-memory
A VectorStore() instance. Defaults to in-memory with all-minilm-l6-v2 embeddings.
batchSize
Numeric
100
Number of text segments processed per batch during ingestion.
continueOnError
Boolean
false
When true, the ingestion pipeline skips failed segments and continues processing the remaining ones instead of stopping at the first failure.
recursive
Boolean
false
When true, document loading traverses subdirectories under the given path. When false, loading is limited to the top-level directory only.

Return Value

Returns a SimpleRAGService object. Call .ingest() or .ingestAsync() before querying.

Usage

Note: The in-memory vector store is used as the default when only two parameters are supplied. Ingested documents are wiped from in-memory storage if the server restarts. Use a persistent vector store for production deployments.

Examples

Example 1- Minimal usage (two parameters)
// Minimum required: source path + model config
modelConfig = {
    provider:   "openai",
    credential: "sk-your-api-key"
};

ragBot = SimpleRAG("./docs/", modelConfig);
ragBot.ingest();

answer = ragBot.ask("What are the system requirements?");
writeOutput(answer.message);
Example 2- Enterprise vector store with async ingestion
chatModel = ChatModel({
    provider: "openai",
    model:    "gpt-4",
    apiKey:   "sk-your-api-key"
});

vectorStoreClient = VectorStore({
    provider:   "qdrant",
    url:        "http://enterprise-qdrant.internal:6333",
    collection: "cf_documentation",
    embeddingModel: {
        provider: "openai",
        model:    "text-embedding-3-large",
        apiKey:   "sk-your-api-key"
    }
});

ragBot = SimpleRAG("./docs/", chatModel, {
    vectorStore:  vectorStoreClient,
    chunkSize:    1500,
    chunkOverlap: 200,
    maxResults:   10,
    minScore:     0.6
});

// Non-blocking ingestion
future = ragBot.ingestAsync();
result = future.get();

response = ragBot.ask("How do I use cfquery?");
writeOutput(response.message);
Example 3- Custom splitter options
ragBot = SimpleRAG(expandPath("./docs/"), chatModel, {
    vectorStore:   vs,
    recursive:     true,
    continueOnError: false,
    chunkSize:     500,
    chunkOverlap:  100
});

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page