• 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
5
.vtignore
AGENTS.md
README.md
deno.json
main.tsx
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
/
140
/
code
/
README.md
/
README.md
Code
/
/
x
/
peterqliu
/
PineconeIndex
/
branch
/
main
/
version
/
140
/
code
/
README.md
/
README.md
Search
…
Viewing readonly version of main branch: v140
View latest version
README.md

PineconeIndex

A simple interface for making and querying Pinecone vector databases. Use OpenAI embeddings to vectorize and search

Quickstart

Create keys for Pinecone and OpenAI, and store then in your environment variables. Then,

import PineconeIndex from "https://esm.town/v/peterqliu/PineconeIndex/main.tsx"; // set up your environment variables 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, }); // run this only once await index.create(); // Using the methods directly (see bottom of README for HTTP access) const results = await index.query("machine learning applications"); await index.upsert(["Document 1", "Document 2"]); await index.empty();

The options passed to the constructor are a thin abstraction over options for new Pinecone().createIndex(). For more detail, consult that documentation.

API Reference

index.create()

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

index.query(string)

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

Items### index.upsert(items)

Upload new documents to your index. Accepts an array of strings or objects containing metadata.

If passing objects, each object must contain a text property which will be embedded. The entire object is stored as metadata, which is useful for filtering or retrieving structured data later.

// Option 1: Simple array of strings await index.upsert([ "First document content", "Second document content", ]); // Option 2: Array of objects (entire object is saved as metadata) await index.upsert([ { text: "The quick brown fox", category: "animals", source: "book" }, { text: "Jumped over the lazy dog", category: "animals", rating: 5 } ]);

index.empty()

Remove all documents from your index.

await index.empty();

Remote HTTP access

PineconeIndex also provides handleRequest as a convenience method to access your indices via HTTP. This is useful when accessing the index from other vals, especially without sharing Pinecone and OpenAI credentials.

Server setup

First instantiate your index:

const index = new PinconeIndex({...}); export default async function (req: Request): Promise<Response> { return await index.handleRequest(req); }

Usage

In vals that need to Operations are determined by the URL path (/query, /upsert, /clear). The first segment after the domain specifies the operation to perform.

const API_URL = "https://index-val-url.web.val.run"; // Search for documents: append the desired operation to the url const searchResponse = await fetch(`${API_URL}/query/`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify("artificial intelligence trends"), });
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.