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: v89View latest version
A simple HTTP interface for querying and managing your Pinecone vector database. Search through your documents using natural language queries via REST API endpoints.
-
Set Environment Variables
PINECONE_KEY: Your Pinecone API keyOPENAI_KEY: Your OpenAI API key
-
Use the API
# Search your documents curl -X POST https://your-val-url.web.val.run/query/ \ -H "Content-Type: application/json" \ -d '"machine learning applications"'
Find the most relevant documents for your query.
POST /query/
Request Body:
"your search query here"
or
{ "query": "your search query here" }
Response:
{ "matches": [ { "id": "doc-123", "score": 0.95, "metadata": { "text": "Machine learning is transforming..." } } ] }
Upload new documents to your index.
POST /upsert/
Request Body:
{ "texts": [ "First document content", "Second document content" ] }
Response:
{ "success": true, "count": 2 }
Remove all documents from your index.
POST /empty/
Response:
{ "success": true, "message": "Index cleared" }
Check if the service is running and configured properly.
GET /health/
Response:
{ "status": "healthy", "timestamp": "2025-12-20T19:21:17.737Z", "config": { "pineconeKey": "✓ Set", "openaiKey": "✓ Set" } }
const API_URL = 'https://your-val-url.web.val.run';
// Search for documents
async function search(query) {
const response = await fetch(`${API_URL}/query/`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(query)
});
return response.json();
}
// Add new documents
async function addDocuments(texts) {
const response = await fetch(`${API_URL}/upsert/`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ texts })
});
return response.json();
}
// Example usage
const results = await search('artificial intelligence trends');
await addDocuments(['AI is revolutionizing healthcare', 'Machine learning in finance']);
import requests API_URL = 'https://your-val-url.web.val.run' # Search documents def search(query): response = requests.post(f'{API_URL}/query/', json=query) return response.json() # Add documents def add_documents(texts): response = requests.post(f'{API_URL}/upsert/', json={'texts': texts}) return response.json() # Example usage results = search('climate change solutions') add_documents(['Solar energy is becoming more efficient', 'Wind power costs are decreasing'])
# Search curl -X POST https://your-val-url.web.val.run/query/ \ -H "Content-Type: application/json" \ -d '"renewable energy technologies"' # Add documents curl -X POST https://your-val-url.web.val.run/upsert/ \ -H "Content-Type: application/json" \ -d '{"texts": ["Document 1", "Document 2"]}' # Clear index curl -X POST https://your-val-url.web.val.run/empty/ # Health check curl https://your-val-url.web.val.run/health/
The API returns standard HTTP status codes:
200- Success400- Bad Request (missing required fields)405- Method Not Allowed (wrong HTTP method)500- Server Error (API key issues, service problems)
Error responses include helpful messages:
{ "error": "Query text is required", "hint": "Make sure PINECONE_KEY and OPENAI_KEY environment variables are set" }
The service uses these default settings:
- Index:
wikipedia-simple-text-embedding-ada-002-250k - Model:
text-embedding-ada-002 - Dimensions: 1536
- Results: Top 10 matches per query
To customize these settings, modify the PineconeIndex configuration in the code.