-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from philippgille/add-minimal-example
Add minimal example
- Loading branch information
Showing
4 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => ./../.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
} |