• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
peterqliu

peterqliu

PineconeIndex

Vector db's on Pinecone, with OpenAI embeddings
Public
Like
PineconeIndex
Home
Code
3
PineconeIndex
README.md
H
sample_server
Branches
1
Pull requests
Remixes
History
Environment variables
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.
Sign up now
Code
/
/
x
/
peterqliu
/
PineconeIndex
/
branch
/
main
/
version
/
90
/
code
/
README.md
/
README.md
Code
/
/
x
/
peterqliu
/
PineconeIndex
/
branch
/
main
/
version
/
90
/
code
/
README.md
/
README.md
Search
…
Viewing readonly version of main branch: v90
View latest version
README.md

PineconeIndex HTTP API

A simple HTTP interface for querying and managing your Pinecone vector database. Search through your documents using natural language queries via REST API endpoints.

Creating Your Own Instance

To use PineconeIndex in your own Val Town project:

import PineconeIndex from "https://esm.town/v/peterqliu/PineconeIndex/PineconeIndex"; const index = new PineconeIndex({ name: "my-index-name", // Your Pinecone index name model: "text-embedding-ada-002", // OpenAI embedding model dimensions: 1536, // Vector dimensions (1536 for ada-002) pineconeKey: Deno.env.get("PINECONE_KEY"), modelToken: Deno.env.get("OPENAI_KEY"), namespace: "optional-namespace" // Optional: isolate data within index }); // Use directly in code const results = await index.query("search text"); await index.upsertRecords(["doc 1", "doc 2"]); // Or create HTTP endpoints export default async function(req: Request) { return await index.handleRequest(req); }

Configuration Options

OptionRequiredDescription
name✓Your Pinecone index name
model✓OpenAI embedding model (e.g., "text-embedding-ada-002")
dimensions✓Vector dimensions (1536 for ada-002, 3072 for ada-003)
pineconeKey✓Your Pinecone API key
modelToken✓Your OpenAI API key
namespaceOptional namespace to isolate data within the index

Quick Start

  1. Set Environment Variables

    • PINECONE_KEY: Your Pinecone API key
    • OPENAI_KEY: Your OpenAI API key
  2. 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"'

API Reference

Search Documents

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..." } } ] }

Add Documents

Upload new documents to your index.

POST /upsert/

Request Body:

{ "texts": [ "First document content", "Second document content" ] }

Response:

{ "success": true, "count": 2 }

Clear Index

Remove all documents from your index.

POST /empty/

Response:

{ "success": true, "message": "Index cleared" }

Health Check

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" } }

Usage Examples

JavaScript

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']);

Python

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'])

cURL

# 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/

Error Handling

The API returns standard HTTP status codes:

  • 200 - Success
  • 400 - 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" }

Configuration

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.

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.