You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorial/markdown/nodejs/quickstart-mastra/mastra-couchbase-nextJS-tutorial.md
+23-3Lines changed: 23 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,7 +149,17 @@ export const researchAgent = new Agent({
149
149
}),
150
150
});
151
151
```
152
-
Here, we define an `Agent` that uses the `gpt-4o-mini` model, has a clear set of instructions for its personality and task, and is equipped with a `vectorQueryTool` to find information. It also uses `LibSQLStore`for memory, allowing it to remember conversation history.
152
+
Here, we define an `Agent` with several key components that work together to create an intelligent research assistant:
153
+
154
+
- **Model**: Uses OpenAI's `gpt-4o-mini` for generating responses. This is a cost-effective model that provides good performance for question-answering tasks while keeping API costs manageable.
155
+
156
+
- **Instructions**: Clear personality and task guidelines that shape how the agent behaves. These instructions tell the agent to act as a research assistant, focus only on information from the uploaded documents, and always cite sources when providing answers.
157
+
158
+
- **Tools**: Equipped with `vectorQueryTool` to search through your uploaded documents. When a user asks a question, the agent automatically uses this tool to find relevant chunks of text from the PDFs you've uploaded, then bases its answer on that retrieved content.
159
+
160
+
- **Memory**: Uses `LibSQLStore` to remember conversation history across chat sessions. This creates a local SQLite database file (`memory.db`) that persists all chat messages, allowing the agent to reference earlier parts of the conversation and maintain context.
161
+
162
+
The LibSQL database automatically handles storing and retrieving chat messages in the background. This means users can ask follow-up questions like "Can you elaborate on that?" or "What did you say about X earlier?" and the agent will understand what they're referring to from the conversation history.
This tool uses the `ai` SDK to create an embedding for the search query and then uses our Couchbase vector store to find the most relevant text chunks.
212
+
This tool leverages the `ai` SDK to generate embeddings for user search queries and then utilizes our Couchbase vector store to perform semantic search and retrieve the most relevant text chunks. The process involves:
213
+
214
+
1. **Query Embedding**: The tool takes the user's natural language query and converts it into a high-dimensional vector representation using the same embedding model that was used to process the original documents.
215
+
216
+
2. **Vector Search**: The embedded query is then used to search the Couchbase vector database, which compares the query vector against all stored document embeddings using similarity metrics (cosine similarity, euclidean distance, or dot product).
217
+
218
+
3. **Result Ranking**: Couchbase returns the most similar document chunks ranked by their similarity scores, allowing the tool to identify the most relevant information for the user's query.
219
+
220
+
4. **Score Filtering**: The tool applies a minimum similarity threshold (defaulting to 0.1) to ensure only sufficiently relevant results are returned, filtering out low-quality matches.
221
+
222
+
This vector search capability is what enables the RAG system to ground AI responses in specific, relevant information from the uploaded documents rather than relying solely on the model's pre-trained knowledge.
203
223
204
224
---
205
225
@@ -347,7 +367,7 @@ This separation of concerns allows the backend to focus on the heavy lifting of
347
367
You can extend the `readDocument`functionin`ingestPdf/route.ts` to support other file types like `.docx` or `.txt` by using different parsing libraries.
348
368
349
369
### Advanced Mastra Features
350
-
Explore more of Mastra's capabilities by creating multi-agent workflows, adding more custom tools (e.g., a tool to perform web searches), or implementing more sophisticated memory strategies.
370
+
Explore more of Mastra's capabilities by creating [multi-agent workflows](https://mastra.ai/en/docs/workflows/using-with-agents-and-tools), adding more [custom tools](https://mastra.ai/en/docs/tools-mcp/overview) (e.g., a tool to perform web searches), or implementing more sophisticated [memory strategies](https://mastra.ai/en/docs/memory/overview).
351
371
352
372
### Enhanced Vector Search
353
373
Improve retrieval by experimenting with hybrid search (combining vector search with traditional keyword search), filtering by metadata, or implementing more advanced chunking and embedding strategies.
0 commit comments