Multiple Documents
Ragapi supports storing and interacting with multiple documents within the same namespace. By organizing multiple documents under a shared namespace, you can chat with them collectively, making it easy to access and query information from various sources simultaneously. This feature allows you to combine different context types, such as PDFs, GitHub repositories, YouTube videos, and websites, within a single namespace.
Storing Multiple Documents
To store multiple documents together, simply specify the same pineconeNamespace
for each document when using the /store-document
endpoint. Each document added with this shared namespace becomes part of the same data collection, making it accessible within a unified query space.
You can call multiple /store-document
requests concurrently.
Chatting with Multiple Documents
When you pass the same pineconeNamespace
to the /conversation
endpoint, you’ll be able to chat with all documents stored within that namespace. Ragapi will retrieve relevant information from each document within the namespace, allowing you to seamlessly interact with all stored content as if it were a single knowledge base.
Example Use Case
- Storing Documents: Store a PDF, a GitHub repository, and a website under the namespace
"project-resources"
. - Querying the Collection: Use the
/conversation
endpoint with the samepineconeNamespace
("project-resources"
) to ask questions that draw on information from any of these sources.
Combining Context Types
Ragapi supports combining all context types within a single namespace. This means you can store and query a mix of document types (e.g., pdf
, github_repo
, youtube_video
, website
) together, providing a versatile and rich foundation for querying across various information sources.
By organizing your documents this way, you can streamline access to diverse types of data and interact with them seamlessly, enhancing the depth and utility of your queries.
Example
Let's first define a function for storing documents:
const storeDoc = async (pineconeNamespace, documentUrl, contextType) => {
const serviceUrl = "https://api.ragapi.tech/store-document"
const apiKey = "YOUR_RAGAPI_API_KEY"
const pineconeIndexName = "YOUR_PINECONE_INDEX"
const response = await fetch(serviceUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": apiKey,
},
body: JSON.stringify({
pineconeIndexName,
pineconeNamespace,
documentUrl,
contextType,
}),
})
}
Now, we need a function for asking questions:
const conversation = async (pineconeNamespace, query) => {
const serviceUrl = "https://api.ragapi.tech/conversation"
const apiKey = "YOUR_RAGAPI_API_KEY"
const pineconeIndexName = "YOUR_PINECONE_INDEX"
const response = await fetch(serviceUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": apiKey,
},
body: JSON.stringify({
pineconeIndexName,
pineconeNamespace,
query,
}),
})
const result = await response.json()
return result.data.answer
}
And now, let's call them:
const multiContextChat = async () => {
console.log("Storing documents...")
await Promise.all([
storeDoc(
"same-namespace", // this is important - storing and querying within the same namespace
"https://core.ragapi.tech/storage/v1/object/public/ragapi-public/example.pdf",
"pdf"
),
storeDoc(
"same-namespace",
"https://www.youtube.com/watch?v=yqr6yLyuHQA",
"youtube_video"
),
])
console.log("Asking questions...")
const answerPdf = await conversation(
"same-namespace",
"Where does Ignatius the blockchain come from?"
)
console.log(answerPdf) // Northern Highlands
const answerYoutube = await conversation(
"same-namespace",
"Who graduated 10 years ago?"
)
console.log(answerYoutube) // Priscilla
}
multiContextChat()
As you can see, you can call multiple /store-document
requests at the same time. Having separated calls is also useful for progress trackers, because you can have a separate loading state for each document.