Your First AI Application With Smarter, Part 6: Searching Your Own Documents With a Vectorstore
A Smarter Vectorstore is a vector database, declared in a YAML manifest, that holds your own documents so that a language model can answer from them, a technique called retrieval-augmented generation, or RAG. In Part 5, four guardrails made Stanley, Stackademy’s course advisor, safe to put in front of students. He knows Stackademy’s courses, their prices and what to take first. He doesn’t know Stackademy’s rules. In this part, he learns to search Stackademy’s student handbook, and to answer questions about refunds, extensions, grading and certificates from its own words.

A question Stanley can’t answer
Ask Stanley something any student might ask.
I’m sick and need more time to finish my course. Can I get an extension?
His guardrail from Part 5 answers for him.
I can only help with Stackademy’s courses. Ask me what to study, what a course costs, or what to take first.
The stackademy_topics judge was told that Stanley helps with courses, prices, prerequisites and choosing what to study, so an extension is out of scope. That’s the guardrail doing its job. And if it let the question through, Stanley would have nothing to answer from. Stackademy’s extension policy isn’t in the course catalogue, or the course database, or the model’s training data. His system prompt tells him to say so and never guess, which is the right answer for an advisor with no handbook.
Stackademy’s handbook is a Markdown file, stackademy-handbook.md. Download it into the folder that holds your manifests. It’s short, six sections on enrollment and refunds, extensions, grading and certificates, the AI Engineering Certificate, accessibility and academic honesty. Here’s its section on extensions.
## Extensions
If you need more time, you can ask your instructor for one extension of up to 4 weeks per course. Ask before your
16 weeks end. A second extension needs the approval of the Dean of Students, and is given only for illness, family
emergencies or military service.
A handbook this small would fit in Stanley’s system prompt. A real one, with hundreds of pages of policies, manuals and course notes, wouldn’t, and every prompt would pay for all of it. A Vectorstore sends the model only the few passages that a question needs.
How a Vectorstore finds the right passage
When you add a document, Smarter extracts its text and splits it into chunks of about 1,000 characters, overlapping a little so that no sentence is lost at a boundary. An embeddings model turns each chunk into a vector, a list of 1,536 numbers that places the chunk’s meaning in space. Chunks about similar things land near each other. The vectors go into the database’s index.
When Stanley searches, he writes a query, and the same embeddings model turns the query into a vector. The database returns the chunks whose vectors are nearest to it, each with a similarity score, and Stanley answers from them.

A search by meaning finds the refund policy for a student who asks about getting their money back, although the handbook never says “money back”. A keyword search wouldn’t.
Create the Vectorstore
Save this as stackademy-handbook-store.yaml.
apiVersion: smarter.sh/v1
kind: Vectorstore
metadata:
name: stackademy_handbook
description: Stackademy's student handbook and policies.
version: 1.0.0
spec:
backend: pinecone
hosting: managed
connection: pinecone
index:
dimension: 1536
metric: cosine
deletionProtection: false
embeddings:
provider: openai
model: text-embedding-3-small
pinecone:
cloud: aws
region: us-east-1
maintenance:
snapshots: false
backend: pineconeandhosting: managedput the index in Pinecone, a hosted vector database. Smarter can also run Qdrant for you, on its own Kubernetes cluster, or use Qdrant Cloud.connection: pineconenames the ApiConnection that holds the platform’s Pinecone api key. A platform creates it from the Pinecone key that its operator configured, so you never see the key.index.dimensionmust match the embeddings model. OpenAI’stext-embedding-3-smallmakes vectors of 1,536 numbers.metric: cosinecompares them by the angle between them, which is what this model is built for.embeddingsis the model that embeds both the documents and every query. It’s a Provider’s model, like Stanley’s own.pinecone.cloudandregionsay where the index lives. Pinecone’s free plan offers AWSus-east-1.
Apply it, then deploy it.
smarter apply -f stackademy-handbook-store.yaml
smarter deploy vectorstore stackademy_handbook
Applying a Vectorstore records it. Deploying it creates the database, and that’s when it starts to cost money, if it’s ever going to. A new Pinecone index takes a minute or two to initialize, so deploy returns at once and Smarter finishes the job in the background. Follow it with describe, until its status is ready.
smarter describe vectorstore stackademy_handbook
status:
conditions:
- message: Pinecone accepted the api key.
reason: Accepted
status: "True"
type: Credentials
- message: stackademy-handbook-314159265359 is ready.
reason: Ready
status: "True"
type: Index
documentCount: 0
vectorCount: 0
vectorstoreStatus: ready
Each condition is one thing that the database needs. If Pinecone refused the key, or the index never came up, the condition that failed would say so, in words.
Add the handbook
Smarter’s command-line tool has a documents command for exactly this. You need version 0.6.0 or later (smarter version tells you).
smarter documents vectorstore stackademy_handbook --add stackademy-handbook.md
It answers with the Vectorstore’s documents, and a message.
"message": "Added 1 document to Vectorstore stackademy_handbook."
Smarter extracts the text, and a background worker splits, embeds and loads it. The handbook took about four seconds. Run the command again without --add to list the Vectorstore’s documents and see each one’s status.
smarter documents vectorstore stackademy_handbook -o yaml
documents:
- name: stackademy-handbook.md
contentType: text/markdown
sizeBytes: 2008
chunkCount: 3
source: upload
status: loaded
vectorstore: stackademy_handbook
The handbook’s 2,008 bytes became three chunks. The command also takes PDFs, plain text, CSV, JSON, YAML and HTML files, and a public url with --url. Adding the same text twice does nothing, because Smarter recognizes it, and --remove stackademy-handbook.md takes a document out again. The web console does all of this too. Open the Vectorstore’s details and drop a file on its Documents section.

The original file is never stored, only its extracted text, so a confidential document doesn’t end up in a file bucket somewhere.
Give Stanley a way to search it
A Vectorstore holds documents. A Vectorsearch is a named way of searching one, and it’s what an LLMClient uses. Save this as handbook-search.yaml.
apiVersion: smarter.sh/v1
kind: Vectorsearch
metadata:
name: handbook_search
description: >
Searches Stackademy's student handbook, for its policies on enrollment, refunds, transfers, extensions,
grading, certificates, accessibility and academic honesty.
version: 1.0.0
spec:
config:
vectorstore_name: stackademy_handbook
search_type: similarity
k: 4
is_enabled: true
descriptionis the most important line in the file. Stanley’s model reads it, and nothing else, to decide when to search, so it says what the documents are and what they answer. It’s the same job as an ApiPlugin’s description in Part 3.k: 4returns at most the four closest chunks. The handbook only has three, so every search returns all of them, in order. With a real handbook,kkeeps the prompt small.search_type: similarityreturns the nearest chunks.mmr, maximal marginal relevance, trades a little similarity for variety, which helps when many chunks say nearly the same thing.
Apply it.
smarter apply -f handbook-search.yaml
Widen Stanley’s scope
Stanley’s guardrail still blocks the extension question. In Part 5, the judge’s prompt described what Stanley may help with, as a rule. The rule needs one more item now. Open stackademy-topics.yaml, add Stackademy’s student policies to the scope, and change its version to 1.1.0.
judgePrompt: |-
You are a scope classifier for Stanley, the student advisor of Stackademy, an
online code academy. Stanley may help only with Stackademy's courses, their
subjects, prices and prerequisites, choosing what to study, and Stackademy's
student policies, such as enrollment, refunds, extensions, grading,
certificates, accessibility and academic honesty.
Apply it.
smarter apply -f stackademy-topics.yaml
Every time an application learns something new, its guardrails need to learn that it’s allowed. Test both sides again, as in Part 5. The capital of France is still blocked, and the extension question goes through.
Give Stanley the Vectorsearch
Add a vectorsearches list to course-advisor.yaml, at the same level as plugins and guardrails, and change its version to 1.5.0.
vectorsearches:
- handbook_search
Apply it, and commit.
smarter apply -f course-advisor.yaml
git add .
git commit -m "A student handbook for Stanley"
Ask him about the rules
Open Stanley in a new chat and ask this.
Can I get a refund if I’ve already done two assignments?
Stanley searched the handbook before he answered. The chat shows the search as a tool call, with the query that the model wrote.
openai called this tool: handbook_search({"query":"refund eligibility after completing two assignments in a course"})
The search isn’t the student’s question. The model writes its own query, in the handbook’s terms, and the search returns three passages, the closest first, each with its chunk’s text, where it came from, and its score. Here they are, with their text cut short.
{
"vectorsearch": "handbook_search",
"vectorstore": "stackademy_handbook",
"results": [
{
"text": "# Stackademy Student Handbook\n\n## Enrollment and refunds\n\nYou can enroll in a course at any time...",
"metadata": {"chunk": 0, "document": "stackademy-handbook.md", "source": "upload"},
"score": 0.4735412
},
{
"text": "## Grading and certificates\n\nEach course has graded assignments and a final project...",
"metadata": {"chunk": 1, "document": "stackademy-handbook.md", "source": "upload"},
"score": 0.432337105
},
{
"text": "## Academic honesty\n\nYou may use AI coding assistants on assignments unless...",
"metadata": {"chunk": 2, "document": "stackademy-handbook.md", "source": "upload"},
"score": 0.425798267
}
]
}
Yes, if you’re within 30 days of enrolling and have completed no more than two graded assignments, you can request a full refund. Email the registrar at
registrar@stackademy.example.

Every detail of that answer is in the handbook, and none of it is in the model. The scores are modest, because a short query and a 1,000-character chunk are never close to identical. What matters is the order. The refund policy came first.
Ask the extension question from the start of this part, in a new chat, and Stanley gets through his guardrail, searches the handbook and answers.
Yes. You can ask your instructor for one extension of up to 4 weeks per course, as long as you request it before your 16-week course period ends. A second extension requires the Dean of Students’ approval and is granted only for illness, family emergencies, or military service.
Answers that searched a Vectorstore are never served from Smarter’s cache of first answers, because the documents behind them can change.
One question, three tools
Stanley now has three kinds of tools, a REST API from Part 3, a SQL database from Part 4, and the handbook. He decides which to use, and he can use all of them for one question.
What do I need to do to earn the AI Engineering Certificate, and what will it cost me?
He called five tools for that one. He looked up the AI courses in the catalogue, searched the handbook for the certificate’s requirements, and asked the database for the prerequisites of each of the three courses the certificate needs.

To earn the AI Engineering Certificate, pass Artificial Intelligence (CS210), Machine Learning (CS301), and the AI Capstone Project (CS405) with at least 70% in each.
The prerequisite path is CS101 → CS102 → CS104 → CS107 → CS210 → CS301 → CS405. The three certificate courses cost $2,450; including the prerequisite courses, the full path costs $4,600.
The certificate’s requirements came from the handbook, the path from the database, and the prices from both. I checked his arithmetic against the database ($700 + $750 + $1,000 is $2,450, and the four courses before them add $2,150), and it’s right. The 70% isn’t in the certificate’s section of the handbook. The certificate asks for three passed courses, and the grading section, in another chunk, says that a pass is 70%. Stanley put the two together, which a search for keywords alone wouldn’t have done for him.
The Console’s Architecture tab draws Stanley’s whole application now, with the Vectorsearch and its Vectorstore beside his two plugins.

What’s next
Stanley answers from Stackademy’s course catalogue, its course database and its student handbook, inside guardrails, and every piece of him is a manifest in a git repository. So far he only lives in the workbench. In Part 7, he goes live, deployed at his own url and embedded in Stackademy’s website, where students can find him.
