• 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
/
98
/
code
/
README.md
/
README.md
Code
/
/
x
/
peterqliu
/
PineconeIndex
/
branch
/
main
/
version
/
98
/
code
/
README.md
/
README.md
Search
…
Viewing readonly version of main branch: v98
View latest version
README.md

PineconeIndex

A simple interface for querying and managing your Pinecone vector database. Search through your documents using natural language queries.

Creating Your Own Instance

To use PineconeIndex in your own Val Town project:

import PineconeIndex from "https://esm.town/v/peterqliu/PineconeIndex/PineconeIndex"; const pineconeKey = Deno.env.get("PINECONE_KEY"); const modelToken = Deno.env.get("OPENAI_KEY"); const index = new PineconeIndex({ name: "2025-all-docs", model: "text-embedding-ada-002", dimensions: 1536, pineconeKey, modelToken, }); // Use the methods directly const results = await index.query("machine learning applications"); await index.upsertRecords(["Document 1", "Document 2"]); await index.empty();

API Reference

Search Documents

Find the most relevant documents for your query.

const results = await index.query("your search text");

Returns:

{ "matches": [ { "id": "doc-123", "score": 0.95, "metadata": { "text": "Machine learning is transforming..." } } ] }

Add Documents

Upload new documents to your index.

await index.upsertRecords([ "First document content", "Second document content" ]);

Clear Index

Remove all documents from your index.

await index.empty();

Create Index

Create a new Pinecone index (if it doesn't exist).

await index.create();

Usage Examples

Basic Usage

import PineconeIndex from "https://esm.town/v/peterqliu/PineconeIndex/PineconeIndex"; const index = new PineconeIndex({ name: "my-documents", model: "text-embedding-ada-002", dimensions: 1536, pineconeKey: Deno.env.get("PINECONE_KEY"), modelToken: Deno.env.get("OPENAI_KEY"), }); // Add some documents await index.upsertRecords([ "AI is revolutionizing healthcare", "Machine learning enables automation", "Solar energy is becoming more efficient" ]); // Search for relevant documents const results = await index.query("renewable energy technologies"); console.log(results.matches);

HTTP Server

Create an HTTP endpoint that uses your index:

// query index with string for nearest neighbors export default async function (req: Request): Promise<Response> { return await index.handleRequest(req); }

HTTP API Documentation

When using the HTTP server, operations are determined by the URL path. The first segment after the domain specifies the operation to perform.

URL Structure

https://your-val-url.web.val.run/{operation}/

Where {operation} can be:

  • query - Search for documents
  • upsert - Add new documents
  • empty - Clear the index
  • health - Check server status

HTTP Endpoints

Search Documents

POST /query/ Content-Type: application/json "your search query here"

Response:

{ "matches": [ { "id": "doc-123", "score": 0.95, "metadata": { "text": "Machine learning is transforming..." } } ] }

Add Documents

POST /upsert/ Content-Type: application/json { "texts": [ "First document content", "Second document content" ] }

Response:

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

Clear Index

POST /empty/

Response:

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

Health Check

GET /health/

Response:

{ "status": "healthy", "timestamp": "2025-12-20T19:21:17.737Z", "config": { "pineconeKey": "✓ Set", "openaiKey": "✓ Set" } }

HTTP Usage Examples

JavaScript/Fetch

const API_URL = "https://your-val-url.web.val.run"; // Search for documents const searchResponse = await fetch(`${API_URL}/query/`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify("artificial intelligence trends") }); const results = await searchResponse.json(); // Add documents await fetch(`${API_URL}/upsert/`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ texts: ["AI is revolutionizing healthcare", "Machine learning in finance"] }) }); // Clear index await fetch(`${API_URL}/empty/`, { method: "POST" }); // Health check const healthResponse = await fetch(`${API_URL}/health/`); const health = await healthResponse.json();

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/

Python

import requests API_URL = 'https://your-val-url.web.val.run' # Search documents response = requests.post(f'{API_URL}/query/', json="climate change solutions") results = response.json() # Add documents requests.post(f'{API_URL}/upsert/', json={ 'texts': ['Solar energy is efficient', 'Wind power costs decreasing'] }) # Health check health = requests.get(f'{API_URL}/health/').json()

Error Handling

The HTTP API returns standard 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" }
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.