Getting Started with Ragapi
Welcome to Ragapi! Here’s a simple checklist to help you get started. Follow these six steps to set up your Ragapi API, connect it with your OpenAI and Pinecone accounts, and make your first document query.
Note: This interactive guide is also available in the Ragapi app. As soon as you complete each step, it will automatically check off, helping you keep track of your progress.
Quick Start Checklist
1. Create a Ragapi API Key
To interact with Ragapi, you need a unique API key. You can generate this key in the Ragapi app under API Keys.
2. Add an OpenAI API Key
Ragapi uses OpenAI's API to process document embeddings and generate responses. You’ll need to add your OpenAI API key to your Ragapi account.
- If you don’t have an OpenAI API key, see how to create one here.
3. Add a Pinecone API Key
Ragapi uses Pinecone to store document embeddings in a vector database, making it possible to retrieve relevant information efficiently.
- If you don’t have a Pinecone API key, see how to create one here.
4. Generate Your First Pinecone Index
Create an index in Pinecone to store your document embeddings. When setting up your Pinecone index, make sure that the dimensions are set to 3072 (this aligns with the text-embedding-3-large
model used by OpenAI). You can generate the index via Pinecone app or with the code. See more here.
5. Store Your First Document
With the keys set up, you’re ready to store a document! Here’s how to call Ragapi’s /store-document
endpoint to store a PDF, website, GitHub repo, or YouTube video.
Note: For security reasons, this should be done on the server side. Your Ragapi API key should not be exposed in client-side code.
const serviceUrl = "https://api.ragapi.tech/store-document"
const apiKey = "YOUR_RAGAPI_API_KEY"
const pineconeIndexName = "YOUR_PINECONE_INDEX"
const documentUrl =
"https://core.ragapi.tech/storage/v1/object/public/ragapi-public/example.pdf"
const response = await fetch(serviceUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": apiKey,
},
body: JSON.stringify({
pineconeIndexName,
documentUrl,
contextType: "pdf",
}),
})
const result = await response.json()
// Pinecone index is separated by namespaces.
// You need to pass the namespace to query documents inside.
console.log(result.data.pineconeNamespace)
6. Ask Your First Question!
Now that your document is stored, you can chat with it. Use the /conversation
endpoint to ask questions and retrieve answers based on the stored content.
const serviceUrl = "https://api.ragapi.tech/conversation"
const apiKey = "YOUR_RAGAPI_API_KEY"
const pineconeIndexName = "YOUR_PINECONE_INDEX"
const pineconeNamespace = "NAMESPACE_FROM_PREVIOUS_STEP"
const query = "Where does Ignatius the blockchain come from?"
const response = await fetch(serviceUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": apiKey,
},
body: JSON.stringify({
pineconeIndexName,
pineconeNamespace,
query,
}),
})
const data = await response.json()
// Should contain "Northern Highlands"
console.log(data.response)
Congratulations! 🎉
You’re now set up with Ragapi. You’ve created your API key, added OpenAI and Pinecone keys, stored a document, and made your first query. For more advanced usage, refer to the full Ragapi documentation.
Happy coding!