Code Monkey home page Code Monkey logo

basic-ai-examples's Introduction

Basic AI Examples

This is a collection of basic samples that progressively add more complexity. Most of the samples use LangChain. The goal is to progressively cover topics from simple model io, to splitting text and creating embeddings, to interacting with a vector store and doing semantic search, to building out custom RAG (Retrieval Augmented Generation) using a variety of combinations of embedding libraries, vector stores, and LLMs.

Before running any of the examples...

Install the dependencies:

Python

pip install langchain
pip install langchain-openai
pip install sentence_transformers
pip install chromadb

Javascript

npm install

Setup .env config

Rename .env-rename-me to .env. If you're running the examples using OpenAI, make sure to add your api key to the .env file (replace the key thats already there).

Setup ChromaDB

When using ChromaDB as a vector store, you have several options: run it in a container locally, or run it in a container in a cloud provider...running ChromaDB is required for the chroma client to connect (either using the ChromaDB library directly), or via LangChain. To run the container:

docker run -d -p 8000:8000 chromadb/chroma

Setup OpenSearch

When using OpenSearch as a vector store and/or documnt index, for supporting semantic/neural search, k-nn indexes, and all the great functionality OpenSearch offers for the RAG/Semantic Search stack...you will need to initialize your cluster for neural search, configure a model for creating embeddings, and setup an ingestion pipeline to generate vectors when adding documents, etc. It is well documented in the neural search tutorial on the open search site, but I have put together a Postman collection to perform all the tasks necessary in order, including creating an index that supports neural search and some test queries. In opensearch-initialize-neural-search-for-cluster.json there is a collection of tasks to perform from 0-14 in order.

You can run this against a cluster, or a single-node OpenSearch (development) instance. To get up and running quickly, it is recommended to run OpenSearch in a docker container in a "single-node" configuration. It is documented on the Installing OpenSearch page, but to run a single-node config, the command is:

docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:2.11.1

You will need to swap out the IDs used by the different postman requests, such as the model ids, model group ids, ingestion pipeline ids, etc. You can grab each ID from the step previous to it being necessary as you run each step.

Note: the default security is Basic Auth with admin:admin as the username/password.

basic-ai-examples's People

Contributors

mmacmillan avatar

Stargazers

 avatar

Watchers

 avatar Kostas Georgiou 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.