StackSpot AI was designed to streamline repetitive tasks and boost team performance. Some of the tool’s resources, such as Knowledge Source, are essential for teams aiming to optimize practices and ensure the quality of their products, code writing standards, documentation, testing, and other routine activities.
This article will explore good practices for using Knowledge Sources and outline strategies to help artificial intelligence provide more assertive responses to Quick Commands and AI Agents.
What is a Knowledge Source?
A Knowledge Source is a StackSpot AI resource that serves as a customizable source of knowledge that can be adapted to the team’s development and documentation standards and practices.
Building a knowledge base aligned with the team’s standards makes AI hyper-contextualized — aware of the company’s standards and generating answers based on them.
The Knowledge Source is essential for centralizing and sharing knowledge within StackSpot AI, enhancing efficiency and quality in software development.
To learn more about Knowledge Source and how to build a knowledge base, refer to the official StackSpot AI documentation. This article will focus on how we can use this resource more effectively and make better use of StackSpot AI.
We’ll use examples from an Angular project and the creation of an automated test with Cypress, though the knowledge base construction pattern can be applied to any other type of knowledge.
Building a Knowledge Source
When incorporating a Knowledge Source, it is recommended to insert ready-made code without comments or to copy ready-made documentation. While this approach can yield good results with AI, we are aiming for more precise and relevant answers.
A good practice for embedding Knowledge Source is to create a document, ideally in Markdown format, following this pattern:
- Title: Make an apparent reference to the content of the document.
- Description: Right after the title, include a brief description of what will be covered.
- Sections: Divide the content into small sections, each with a subtitle that describes what will be covered.
Example document
Here’s an example of a document with knowledge about automated testing with Cypress, illustrating the team’s standard for mapping HTML elements so that the AI can leverage this knowledge and deliver answers following the standard:
# Squad Starwars: how to map HTML elements in cypress
## Introduction
This document shows how the Starwars squad maps HTML objects to the xpath to be used in cypress for automated tests using the “page objects” pattern.
## Search screen example
const buscaPage = {
btnVoltar: () =>
cy.xpath(“//span[@aria-hidden=’true’][contains(.,’seta_esquerda’)]”),
titleH1: () =>
cy.xpath(
“//main/section/h1[contains(.,’Titulo da pagina de busca’)]”
),
lupaIcon: () =>
cy.xpath(“//span[@aria-hidden=’true’][contains(.,’busca_outline’)]”),
}
In the example, we created a single document to demonstrate how to locate HTML elements using XPath. Keywords such as the squad’s name, “Starwars,” and the technology, “Cypress,” were included. Additional keywords to consider include “mapping” and “page objects.”
Here’s another example of a Markdown document for a knowledge base:
# Knowledge base for the use of jest by the Starwars squad
## Introduction
This document describes how the Starwars squad uses jest to create mocks, use spyOn and use jest.fn
### Example of how to use jest’s spyOn for functions and validate the call in the unit test expectation
import { ModelDependencia } from ‘@dependencia/sdk’;
const spyfunc = jest.spyOn(ModelDependencia, ‘func’).mockReturnValue(of({}))
expect(spyfunc).toHaveBeenCalled()
In the example above, we outlined how Jest is utilized in unit tests, consistently applying keywords to better guide the AI.
Another advantage of using Knowledge Source is that it familiarizes the AI with the project’s code. For instance, if the squad’s standard is to implement a file containing reusable mocks for unit tests, it’s enough to create a document with examples of how to import and use these mocks in the tests.
Therefore, when generating unit tests, the AI will not create new mocks but will use the imports and apply them as instructed.
New example
Let’s take a look at another example:
# Starwars squad knowledge base for creating and using mocks in unit tests
## Introduction
This document describes the standard for creating service mocks and how mocks are used in unit tests generated by the Starwars squad
## Example of how to create a service mock
export const usuarioServiceMock = {
gerarDadosUsuario: jest.fn().mockReturnValue({}),
criarNovoUsuario: jest.fn().mockReturnValue({}),
};
## Example of how to use mocks in Angular component unit tests
import * as mocks from ‘../../../shared/mocks/mocks’;
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
declarations: [UsuarioComponent],
providers: [
{ provide: UsuarioService, useValue: mocks.usuarioServiceMock },
],
});
By structuring the knowledge base as shown in the example above, the AI will not create new mocks when asked to generate unit tests for components that consume the UserService or other services. Instead, it will use imports from existing mocks while maintaining the unit testing pattern adopted by the squad.
Contextualizing the Knowledge Source
Another good practice for utilizing knowledge bases is to make them more contextualized. For example, it is advisable to create separate knowledge bases for different areas, such as:
- Front-end unit testing;
- Front-end component development patterns;
- Back-end unit tests;
- Automated testing with Cypress;
- Writing user stories;
By separating the knowledge bases in this way, it is possible to improve the AI’s contextualization, resulting in more assertive responses aligned with each team’s needs.
More good practices
For effective and user-friendly Knowledge Sources, check out essential aspects to take into account when creating and maintaining content:
- Ensure the Knowledge Source is relevant and up-to-date;
- Review and update it regularly;
- Organize the content logically;
- Use clear and direct language;
- Avoid jargon and unnecessary technical terms;
- Include practical examples and use cases;
- Gather user feedback and make continuous improvements.
When creating or maintaining a Knowledge Source, remember that people of different seniority levels and areas will have access to the content, so write aiming for clarity and inclusivity.
Utilizing the Knowledge Source
So far, we’ve demonstrated how to make Knowledge Sources even more hyper contextualized. The next step is ensuring the AI can leverage this knowledge more assertively.
Returning to the first example: when crafting a prompt that generates the mapping of objects in HTML, use the keywords provided in the knowledge base. Here’s an example:
Option 1: You are a Starwars squad developer; use jest to generate unit tests for the code below.
Option 2: Map HTML elements using Cypress according to the Starwars squad standard.
This approach allows the AI to search for the keywords in the Knowledge Source and generate a more accurate response, avoiding content from other sources already trained on the AI.
In the second example, about creating unit tests with Jest, prompts can be structured as follows:
Option 1: You are a Starwars squad developer, generate unit tests for the code below using jest.
Option 2: Generate unit tests for the following component using jest and following the Starwars squad standards.
By adding these keywords, we “guide” the AI to search for more specific results within the knowledge base.
To make it even easier to use the knowledge base, you can use AI Agents and Quick Commands. Set up prompts with the keywords previously entered into the knowledge base, reducing the need for users to write prompts as everything is pre-configured in the Agent or Quick Command.
Conclusion
The effective use of StackSpot AI Knowledge Sources can transform the way software development teams work. By creating a well-structured and contextualized Knowledge Source, StackSpot AI can deliver more precise answers aligned with the team’s standards and practices.
Adopting good practices when creating documents — such as clear titles, objective descriptions, and well-defined sections— makes organizing and accessing information easier. Separating knowledge bases by specific contexts — such as front-end unit tests, component development, and automated tests— enhances the AI’s contextual understanding, leading to more assertive responses.
To consume these Knowledge Sources efficiently, it is essential to use keywords in prompts, Agents, and Quick Commands, guiding the AI to search for specific information within the knowledge base.
In this way, StackSpot AI becomes a powerful tool for optimizing processes, ensuring code quality, and promoting component reuse, ultimately contributing to success and efficiency in software development.
Did you like these tips? How do you organize your Knowledge Sources? Share your thoughts in the comments!