Giter Site home page Giter Site logo

gpt-vector-db-demo's Introduction

gpt-vector-db-demo

This code is a Node.js script that uses the OpenAI API and Pinecone API to perform various tasks related to text processing, embeddings, and similarity search. The script reads data from a Wikipedia text file, performs cleaning and parsing operations, creates embeddings for the text, uploads the embeddings to a Pinecone index, and provides chat-based responses to user questions based on the indexed data.

Prerequisites

Before running the script, make sure you have the following:

  • Node.js installed on your machine.
  • An OpenAI API key.
  • A Pinecone API key.
  • A Pinecone index name.
  • A Pinecone namespace.

Installation

  1. Clone or download the code from the repository.
  2. Install the required dependencies by running the following command in the project directory:
npm install 

Configure

update the following environment variables:

  • OPENAI_API_KEY: Set your OpenAI API key.
  • PINE_CONE_API_KEY: Set your Pinecone API key.
  • PINE_CONE_INDEX: Set your Pinecone index name.
  • PINE_CONE_NAMESPACE: Set your Pinecone namespace.
  • PINE_CONE_ENVIRONMENT: Set the environment for Pinecone (e.g., 'us-west1').

Make sure to save the changes to the .env file.

Usage

To run the script, execute the following command:

node index.js

The script performs the following tasks:

  1. eads the Wikipedia text from the wikipedia.txt file, cleans the text, and saves the cleaned version to the clean-wikipedia.txt file.
  2. Parses the cleaned text and creates an array of objects containing the parsed lines.
  3. Creates embeddings for each parsed line and uploads them to the Pinecone index.
  4. Prompts the user with a question (Which regions were involved in gallic war ? in the example) and retrieves similar content from the Pinecone index.
  5. Uses the retrieved content as context and the user's question to generate a chat-based response using the OpenAI API.
  6. Displays the response in the console.

Note -: The addEmbeddingToText function is commented out in the code by default. If you want to re-create the embeddings and update the Pinecone index with new data, uncomment the await addEmbeddingToText(index) line in the start function.

Customization

  • You can modify the input question (question) and adjust the similarity threshold (match.score > 0.85) in the getSimilarContent function to control the matching behavior.
  • You can change the OpenAI model used for chat completion by updating the model parameter in the getChatCompletion function.
  • The Pinecone index configuration can be adjusted by modifying the Pinecone client initialization and the uploadTranscriptEmbedding function.

gpt-vector-db-demo's People

Contributors

suyash-thakur avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.