Use Cases + Implementation

How do you build code generation with RAG?

Retrieve before you generate: index internal libraries, API contracts, coding standards and similar existing implementations, then include the most relevant snippets in the prompt. Code RAG reduces invented functions and wrong signatures because the model writes against retrieved interfaces instead of remembered ones. Keep the index current with each merge, and evaluate retrieval quality separately from generation quality.

Key facts

RetrievalPOST /v1/embeddings with plugsky-embed over code, docs and interface definitions
GenerationPOST /v1/chat/completions with retrieved snippets and exact interface signatures
Coding modelsplugsky-coder and plugsky-coder-fast suit generation; the catalogue holds 30+ models
Index unitChunk by function, class or module, keeping signatures and docstrings together
Pricing modelFlat monthly self-serve plans with unlimited fair-use usage
RAG statusRAG is live; embeddings plus chat completions are the building blocks
FreshnessRe-index changed files on merge so retrieval never cites removed APIs
RoadmapBatch ingestion is coming soon; schedule incremental re-indexing yourself

TL;DR

  • Index symbols, not files: one chunk per function or class with its signature.
  • Retrieve exact interfaces and pass them verbatim into the prompt.
  • Exclude generated files, vendored code and anything containing secrets.
  • Re-index on merge; stale interfaces produce confident wrong calls.
  • Score retrieval recall separately from compile and test success.

How it works, step by step

  1. Decide the index scope: private libraries, service contracts, conventions and representative implementations.
  2. Parse symbols and chunk by function, class or module, keeping signatures and docstrings attached.
  3. Embed chunks with plugsky-embed and store metadata: repo, path, symbol, version and last commit.
  4. At generation time, retrieve interfaces and similar implementations under a context budget.
  5. Generate against the retrieved signatures, then compile and test in your pipeline.
  6. Measure retrieval recall and compile rate, and re-index changed paths on every merge.
1Decide the indexscope: privatelibraries, service2Parse symbols andchunk by function,class or module,3Embed chunks withplugsky-embed andstore metadata:4At generation time,retrieve interfacesand similar5Generate againstthe retrievedsignatures, then6Measure retrievalrecall and compilerate, and re-index

Original data

POST /v1/embedRetrievalPOST /v1/chat/Generationplugsky-coder Coding modelsSource: Plugsky facts table · updated 2026-09-25

Try it yourself

Open the vector database comparison →

Why code generation needs retrieval

Public code is in the model's training data; your code is not. Three gaps follow:

  • Private APIs: internal libraries, service clients and platform helpers are invisible to the model, so it invents plausible alternatives.
  • Version drift: a function name or parameter that existed last year may be gone; memories go stale faster than indexes.
  • Conventions: error handling, logging and test structure are house style, and only your repository knows them.

Retrieval closes all three by putting the real signatures and examples in front of the model at generation time, and by making updates an indexing concern rather than a prompt rewrite.

Indexing a codebase

Code has structure; the index should preserve it:

  • Chunk by symbol — function, class, module header — with the signature, docstring and a short usage example in the same chunk.
  • Store canonical metadata: repository, path, symbol name, language, package version and commit hash.
  • Skip generated code, vendored dependencies, test fixtures and minified assets; they crowd retrieval without helping.
  • Never index secrets, environment files or credential material. Scan before embedding.
  • Use incremental indexing keyed by file hash so merges update only what changed.
  • Keep a small set of gold queries and expected symbols to detect index regressions.

Implementation and evaluation

At generation time, retrieval feeds a strict prompt:

  1. Extract symbols and intent from the task to build a precise retrieval query.
  2. Retrieve interfaces first, then similar implementations, under a fixed context budget.
  3. Pass signatures verbatim and instruct the model to call only retrieved symbols.
  4. Compile and test the result; if it calls an unretrieved API, treat that as a retrieval failure, not just a model failure.

Evaluate retrieval recall on a symbol-level gold set, then compile rate and test pass rate on generated code. Attribution matters: if recall is low, a stronger generation model will not fix the problem.

Limitations

Code RAG helps most where interfaces are stable and well-named, and least where logic is the hard part:

  • Retrieval supplies contracts, not comprehension; complex algorithms and cross-module behavior still need human reasoning.
  • Monorepos can exceed practical index sizes, so scope the index per package or team if latency matters.
  • Licensing and provenance rules still apply to any code you index, especially code copied from elsewhere.
  • A stale index produces confidently wrong calls, so treat re-indexing as part of the merge pipeline.
  • Batch ingestion is coming soon, so large initial indexes should be built with your own rate-limited jobs.

Honest comparison

CapabilityCode RAG on PlugskyPrompt with a few open filesFine-tuned code model
Private APIsRetrieved signatures at generation timeOnly files manually pastedIn weights after training
FreshnessRe-index on mergeWhatever the developer selectedRetraining cadence
ConventionsIndexed standards and examplesPartialCaptured if training data includes them
Model choiceCoding models among 30+ aliasesOne modelOne tuned model
EvaluationRecall plus compile and test ratesAd hocHeld-out benchmarks

Frequently asked questions

What should I index for code generation?

Function and class definitions with signatures and docstrings, service contracts, coding standards and a selection of exemplar implementations. Skip generated and vendored code.

How do I chunk source code?

By symbol, not by line count. A function or class with its signature and docstring is a natural retrieval unit and produces cleaner prompts.

Will retrieval stop hallucinated APIs?

It greatly reduces them when the correct interface is retrieved. Instruct the model to use only retrieved symbols, and treat unretrieved calls as retrieval failures to fix.

Which embedding model should I use?

plugsky-embed for English-dominant codebases with English documentation; plugsky-embed-multilingual when comments, docs or identifiers mix languages including Arabic.

How do I keep the index fresh?

Index incrementally on merge using file hashes, and re-embed only changed symbols. Schedule a periodic full reconciliation to catch drift.

Can I use this with plugsky-coder models?

Yes. plugsky-coder and plugsky-coder-fast are the natural generation models, with retrieval supplying the interfaces they should call.

Can I prototype for free?

Yes. Embeddings and chat completions are live, the free plan includes two free models with no card, and the 14-day full-access trial opens the paid catalogue.