Guide
Examples

Examples

To run the included examples, clone this repo, run pnpm install, set up your .env file, and then run an example file using tsx.

Environment variables required to run the examples:

  • OPENAI_API_KEY - OpenAI API key
  • PINECONE_API_KEY - Pinecone API key
  • PINECONE_BASE_URL - Pinecone index's base URL
    • You should be able to use a free-tier "starter" index for most of the examples, but you'll need to upgrade to a paid index to run the any of the hybrid search examples
    • Note that Pinecone's free starter index doesn't support namespaces, deleteAll, or hybrid search :sigh:
  • SPLADE_SERVICE_URL - optional; only used for the chatbot hybrid search example

Basic

npx tsx examples/basic.ts

source (opens in a new tab)

Caching

npx tsx examples/caching.ts

source (opens in a new tab)

Redis Caching

This example requires a valid REDIS_URL env var.

npx tsx examples/caching-redis.ts

source (opens in a new tab)

Chatbot

This is a more involved example of a chatbot using RAG. It indexes 100 transcript chunks from the Huberman Lab Podcast (opens in a new tab) into a hybrid Pinecone datastore (opens in a new tab) using OpenAI ada-002 embeddings (opens in a new tab) for the dense vectors and a HuggingFace SPLADE model (opens in a new tab) for the sparse embeddings.

You'll need the following environment variables to run this example:

  • OPENAI_API_KEY
  • PINECONE_API_KEY
  • PINECONE_BASE_URL
    • Note: Pinecone's free starter indexes don't seem to support namespaces or hybrid search, so unfortunately you'll need to upgrade to a paid plan to run this example. See Pinecone's hybrid docs (opens in a new tab) for details on setting up a hybrid index, and make sure it is using the dotproduct metric.
  • SPLADE_SERVICE_URL
npx tsx examples/chatbot/ingest.ts
npx tsx examples/chatbot/cli.ts

source (opens in a new tab)