Skip to main content

What is Knowledge Source

What are Knowledge Sources?

Knowledge Sources are an essential feature of StackSpot AI that allows the creation of contextualized and personalized chunks of information, it is a knowledge base. They provide additional information, such as code snippets, APIs, and documentation, for example, that StackSpot AI uses to generate more accurate and relevant responses. Creating and adding Knowledge Sources to your Agents, Quick Commands, etc, it enhances StackSpot AI's ability to act as a development assistant, making it more efficient and tailored to your needs.

How do Knowledge Sources work?

When you create a Knowledge Source and add it to an Agent or Quick Command, you provide context to the platform. The AI is enriched with the information you provide. StackSpot AI uses this information to search for similarities in the database and, thus, offer more suitable and contextualized code suggestions.

Types of Knowledge Sources (KS)

  • 1. Snippets Group When you add your code snippets to StackSpot AI, you help create code that mirrors real-world situations and experiences. These snippets enhance the language model's learning process, enabling StackSpot AI to provide more personalized and contextual code suggestions. The advantages include generating code based on real-world situations, the ability to personalize snippets, and improved quality of code suggestions.

Example of a Snippet Group KS: YAML file, a Infrastructure Plugin:

Snippet Code example
schema-version: v3 #required
kind: plugin #required
metadata:
name: ecs-service #required
description: Plugin to create an ECS server #required
display-name: Esc Service #optional
version: 1.0.0 #required
spec:
type: app/infra #required #accepted values: app or infra
compatibility: #optional
- python
docs: #optional
pt-br: docs/pt-br/docs.md
en-us: docs/en-us/docs.md
runtime: #required if the plugin is type: infra
environment: # required for infra Plugins
- terraform-1-4
- aws-cli-2-2
single-use: false #optional #accepted values: true or false
justification: "Justification text" # required
requires: #optional
actions:
- my-studio-slug/my-action-or-plugin-slug
plugins:
- my-studio/single-use-app-plugin
- my-studio/terraform-aws-elasticache-redis
- my-studio/sqs-create-plugin
- studio/plugin
generates: #it only exists if the plugin is type: infra
connections:
- type: aws-iam-role-conn
alias: rds-access-iam-role
outputs:
- from: rds-access-iam-role-arn
to: arn
- type: aws-iam-role-conn
alias: sqs-access-iam-role
outputs:
- from: sqs-access-iam-role-arn
to: arn
links: #optional
- name: Link name
url: Link URL
type: static #static type
picture: icon.png
- name: Link name
url: https://{{connections.rds.host}}.com.br/ #dynamic links use JINJA expressions
type: dynamic #dynamic type
picture: docs/grafana.png
stk-projects-only: true #required #accepted values: true or false
app-allowed: false #it only exists if the plugin is type: infra #accepted values: true or false
inputs: #optional
inputs: #optional
- label: Select the connection for your ecs-task-creator-placeholder
type: required-connection
name: ecs-task-creator-placeholder
connection-interface-type: ecs-task-conn
- label: Select the connection for your ec2-alb-creator-placeholder
type: required-connection
name: ec2-alb-creator-placeholder
connection-interface-type: ec2-alb-conn
- label: Select the connection for your ec2-alb-creator-placeholder2
type: required-connection
name: ec2-alb-creator-placeholder2
connection-interface-type: ec2-alb-conn
- label: Input label
name: Input name
type: text
required: true
default: Input default value
pattern: '([A-Z][a-z]+)+'
help: 'Insert any text'
  • 2. Custom

You can upload files or manually add what you want within your Knowledge Source, such as guides or documents. These will be your Knowledge Objects, which are the chunks of information. StackSpot AI supports the following file types:

  • .json
  • .yml
  • .yaml
  • .md
  • .txt
  • .pdf
  • zip. (The zip. file must contain the supported file types listed above).

Example of a custom KS with React JS best practices:

Best Practices for React DevelopmentProject Structure
Folder Organization: Separate components, pages, services, and styles into distinct folders. Use a folder structure that facilitates scalability and project maintenance.src/ ├── components/ ├── pages/ ├── services/ ├── styles/ ├── utils/ └── App.jsComponents:Create reusable and modular components. Separate presentational components (dumb components) from container components (smart components).
Clean Code
Naming: Use descriptive and consistent names for variables, functions, and components. Use PascalCase for component names and camelCase for variables and functions.Comments:Add comments only when necessary to explain the "why" of the code, not the "how." Keep comments up to date.
Formatting: Use a linter (such as ESLint) and a code formatter (such as Prettier) to maintain code consistency. Configure the linter to follow best practices and coding conventions.State Management
Hooks: Use hooks like useState, useEffect, useContext, etc., to manage state and side effects. Avoid overusing hooks in a single component; consider splitting the component if necessary.
Context API: Use the Context API to manage global states that need to be accessed by multiple components. Avoid overusing contexts; use libraries like Redux or MobX for more complex state management.Styling
CSS Modules: Use CSS Modules for local scope styles to avoid name conflicts. Name style files with the .module.css suffix.
Styled Components: Consider using libraries like Styled Components for component-based styling. Maintain consistency in the chosen styling methodology.Performance
Lazy Loading: Implement lazy loading to improve performance by loading components only when needed.
  • 3. APIs

You can include various OpenAPI (Swagger) files to enhance the coding experience. This allows StackSpot AI to use a catalog of pre-existing APIs, offering code implementations that already integrate these APIs. You'll receive code suggestions utilizing existing APIs and facilitating integration with external services and systems.

This is an example of an API KS in OpenAPI 3.0 format that defines a simple API for user management with GET, POST, PUT, and DELETE operations.

exemplo de API
openapi: 3.0.0
info:
title: My API
description: This is my API
version: 1.0.0
paths:
/users:
get:
operationId: getUser
description: Retrieves a list of users
responses:
'200':
description: Users found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: No users found
post:
operationId: createUser
description: Creates a new user
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'201':
description: User successfully created
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: Invalid data
/users/{userId}:
get:
operationId: getUserById
description: Retrieves a user by ID
parameters:
- in: path
name: userId
schema:
type: integer
required: true
responses:
'200':
description: User found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: User not found
put:
operationId: updateUser
description: Updates an existing user
parameters:
- in: path
name: userId
schema:
type: integer
required: true
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'200':
description: User successfully updated
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: Invalid data
delete:
operationId: deleteUser
description: Deletes a user
parameters:
- in: path
name: userId
schema:
type: integer
required: true
responses:
'204':
description: User successfully deleted
'404':
description: User not found
components:
schemas:
User:
type: object
properties:
id:
type: integer
example: 1
name:
type: string
example: John Doe
email:
type: string
example: john.doe@example.com
phone:
type: string
example: "(11) 555-5555"

Knowledge Source Objects

A Knowledge Object is a component of a Knowledge Source. In StackSpot AI, Knowledge Sources are enhanced by incorporating multiple Knowledge Objects from various sources. Even after creating a Knowledge Source, you can continue to add new objects, expanding the available content and context. For example, when you create a custom Knowledge Source and add new Markdown files, the file is automatically split into multiple Knowledge Objects to optimize token usage and improve the language model's efficiency.

  • The platform supports the following file formats: .json, .yml, .yaml, .md, .txt, .pdf, .zip. The maximum allowed file size is 10 MiB.

How to use Knowledge Sources

Knowledge Sources can be used in different contexts within StackSpot AI, such as:

  • Agents: When creating an Agent, you can assign specific Knowledge Sources to improve the Agent's responses.
  • Quick Commands: Knowledge Sources can provide additional context in Quick Commands, automating tasks based on specific information.
  • IDE: When using the StackSpot AI extension in your IDE, you can select Knowledge Sources to enrich the AI's responses while coding.

Managing Knowledge Sources

You can manage your Knowledge Sources directly on the StackSpot AI Portal. It includes:

  • Updating Knowledge Sources: Adding new Knowledge Objects or modifying existing ones.
  • Deleting Knowledge Sources: Removing Knowledge Sources that are no longer needed.
  • Sharing Knowledge Sources: Sharing Knowledge Sources with other members of your team or account.

Usage Example of KS

You are developing an application that uses several internal APIs from your company. By adding these APIs as Knowledge Sources, StackSpot AI can suggest code implementations that already integrate these APIs, saving time and ensuring that the generated code aligns with your organization's standards.

Learn more