Knowledge Bases
Knowledge bases allow you to store, ingest, and query on your data.
Introduction
What is a knowledge base? A knowledge base consists of a single vector store along with several data connectors that point to different external data sources. As shown in the diagram below, knowledge bases are a fundamental component of the SGP API ecosystem as you need a knowledge base to ingest data through a data connector.
How are knowledge bases related to vector stores? Every knowledge base has one vector store under the hood. Any data that is imported or ingested into a knowledge base will be embedded and stored in its vector store.
How are knowledge bases related to data connectors? When you create a data connector, you associated it with a single knowledge base. Any data that is ingested via that data connector will be stored in its associated knowledge base.
Get Started with the Knowledge Base API
The starter code below creates an SGP knowledge base using the Create Knowledge Base endpoint. Fill in your API key and choose a name for your knowledge base, and try out the starter code below!
import requests
# Replace this with your Spellbook API key
# See instructions for getting your API key here: scale-egp.readme.io/docs/getting-started
API_KEY = '[Your API key]'
# Choose a name for your knowledge base
KNOWLEDGE_BASE_NAME = "my_knowledge_base_1"
# Select an embedding model of the two options listed below
EMBEDDING_MODEL = "openai/text-embedding-ada-002" # or "sentence-transformers/all-MiniLM-L12-v2"
print(f"Creating a knowledge base named {KNOWLEDGE_BASE_NAME}...")
url = "https://api.spellbook.scale.com/egp/v1/knowledge-bases"
payload = {
"knowledge_base_name": KNOWLEDGE_BASE_NAME,
"embedding_model": EMBEDDING_MODEL
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"x-api-key": API_KEY
}
response = requests.post(url, json=payload, headers=headers)
print(f"Response: {response.text}")
You should see a response like the following, which will show your knowledge base ID.
{"knowledge_base_id":"clk123456789"}
Keep this value—you will need it later when getting information about your knowledge base, creating data connectors, and more.
What's Next?
- Ingest data into your knowledge base by using data connectors to ingest external data or uploading local files. You can then query your knowledge base and set up a simple question-answer app.
- Check out our overview on data connectors, which allow you to ingest data from external sources into your knowledge base.
- Check out our API documentation for creating, listing, and deleting knowledge bases.
Updated 4 months ago