Public
Like
PineconeIndex
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v87View latest version
This project provides an HTTP interface for the PineconeIndex class, allowing you to interact with your Pinecone vector database through REST API endpoints.
-
Set your environment variables:
PINECONE_KEY: Your Pinecone API keyOPENAI_KEY: Your OpenAI API key
-
The HTTP server is available at
/pinecone_http_server
GET /health/
Returns the server status and configuration check.
POST /query/
Content-Type: application/json
{
"query": "your search text here"
}
Or simply send a string directly:
POST /query/
Content-Type: application/json
"your search text here"
POST /upsert/
Content-Type: application/json
{
"texts": ["document 1", "document 2", "document 3"]
}
POST /empty/
Clears all vectors from the index/namespace.
// Query the index
const response = await fetch('https://your-val-url.web.val.run/query/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: 'machine learning' })
});
const results = await response.json();
// Add documents
await fetch('https://your-val-url.web.val.run/upsert/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
texts: ['AI is transforming industries', 'Machine learning enables automation']
})
});
# Health check curl https://your-val-url.web.val.run/health/ # Query curl -X POST https://your-val-url.web.val.run/query/ \ -H "Content-Type: application/json" \ -d '{"query": "artificial intelligence"}' # Add documents curl -X POST https://your-val-url.web.val.run/upsert/ \ -H "Content-Type: application/json" \ -d '{"texts": ["Document 1 content", "Document 2 content"]}'
- Automatic routing: The
handleRequestmethod in PineconeIndex automatically routes requests based on URL path - Error handling: Comprehensive error handling with helpful messages
- Flexible input: Query endpoint accepts both string and object formats
- Environment validation: Clear feedback when API keys are missing
- Health monitoring: Built-in health check endpoint
The enhanced PineconeIndex class now includes:
handleRequest(req: Request): Main HTTP router_handleQuery(req: Request): Process query requests_handleUpsert(req: Request): Process document uploads_handleEmpty(req: Request): Process index clearing requests
All existing methods (query, upsertRecords, empty, etc.) remain unchanged and work as before.