Skip to content

Commit

Permalink
Merge pull request #60 from philippgille/add-minimal-example
Browse files Browse the repository at this point in the history
Add minimal example
  • Loading branch information
philippgille authored Mar 23, 2024
2 parents a4ae73e + b57cc35 commit bb2271e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Examples

1. [RAG Wikipedia Ollama](rag-wikipedia-ollama)
1. [Minimal example](minimal)
- A minimal example with the least amount of code and no comments
- Uses OpenAI for creating the embeddings
2. [RAG Wikipedia Ollama](rag-wikipedia-ollama)
- This example shows a retrieval augmented generation (RAG) application, using `chromem-go` as knowledge base for finding relevant info for a question. More specifically the app is doing *question answering*.
- The underlying data is 200 Wikipedia articles (or rather their lead section / introduction).
- We run the embeddings model and LLM in [Ollama](https://github.com/ollama/ollama), to showcase how a RAG application can run entirely offline, without relying on OpenAI or other third party APIs.
2. [Semantic search arXiv OpenAI](semantic-search-arxiv-openai)
- Runs the embeddings model and LLM in [Ollama](https://github.com/ollama/ollama), to showcase how a RAG application can run entirely offline, without relying on OpenAI or other third party APIs.
3. [Semantic search arXiv OpenAI](semantic-search-arxiv-openai)
- This example shows a semantic search application, using `chromem-go` as vector database for finding semantically relevant search results.
- We load and search across ~5,000 arXiv papers in the "Computer Science - Computation and Language" category, which is the relevant one for Natural Language Processing (NLP) related papers.
- Loads and searches across ~5,000 arXiv papers in the "Computer Science - Computation and Language" category, which is the relevant one for Natural Language Processing (NLP) related papers.
- Uses OpenAI for creating the embeddings
16 changes: 16 additions & 0 deletions examples/minimal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Minimal example

This is a minimal example that shows how `chromem-go` works. For more sophisticated examples that use the persistent DB, locally running embedding models, a basic RAG pipeline, with more explanations in the README as well as code comments, check the other examples!

## How to run

1. Set the OpenAI API key in your env as `OPENAI_API_KEY`
2. Run the example: `go run .`

## Output

```text
ID: 1
Similarity: 0.6833369
Content: The sky is blue because of Rayleigh scattering.
```
7 changes: 7 additions & 0 deletions examples/minimal/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/philippgille/chromem-go/examples/minimal

go 1.21

require github.com/philippgille/chromem-go v0.0.0

replace github.com/philippgille/chromem-go => ./../..
44 changes: 44 additions & 0 deletions examples/minimal/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"context"
"fmt"
"runtime"

"github.com/philippgille/chromem-go"
)

func main() {
ctx := context.Background()

db := chromem.NewDB()

c, err := db.CreateCollection("knowledge-base", nil, nil)
if err != nil {
panic(err)
}

c.AddDocuments(ctx, []chromem.Document{
{
ID: "1",
Content: "The sky is blue because of Rayleigh scattering.",
},
{
ID: "2",
Content: "Leaves are green because chlorophyll absorbs red and blue light.",
},
}, runtime.NumCPU())

res, err := c.Query(ctx, "Why is the sky blue?", 1, nil, nil)
if err != nil {
panic(err)
}

fmt.Printf("ID: %v\nSimilarity: %v\nContent: %v\n", res[0].ID, res[0].Similarity, res[0].Content)

/* Output:
ID: 1
Similarity: 0.6833369
Content: The sky is blue because of Rayleigh scattering.
*/
}

0 comments on commit bb2271e

Please sign in to comment.