From acbe5d22ee898657096b544ebc36f134ca1ddbf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Gill=C3=A9?= Date: Sun, 10 Mar 2024 21:12:16 +0100 Subject: [PATCH] Add query performance to examples --- examples/rag-wikipedia-ollama/README.md | 1 + examples/rag-wikipedia-ollama/main.go | 4 ++++ examples/semantic-search-arxiv-openai/README.md | 1 + examples/semantic-search-arxiv-openai/main.go | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/examples/rag-wikipedia-ollama/README.md b/examples/rag-wikipedia-ollama/README.md index 7a30f2e..539e90c 100644 --- a/examples/rag-wikipedia-ollama/README.md +++ b/examples/rag-wikipedia-ollama/README.md @@ -29,6 +29,7 @@ The output can differ slightly on each run, but it's along the lines of: 2024/03/02 20:02:34 Reading JSON lines... 2024/03/02 20:02:34 Adding documents to chromem-go, including creating their embeddings via Ollama API... 2024/03/02 20:03:11 Querying chromem-go... +2024/03/02 20:03:11 Search took 231.672667ms 2024/03/02 20:03:11 Document 1 (similarity: 0.723627): "Malleable Iron Range Company was a company that existed from 1896 to 1985 and primarily produced kitchen ranges made of malleable iron but also produced a variety of other related products. The company's primary trademark was 'Monarch' and was colloquially often referred to as the Monarch Company or just Monarch." 2024/03/02 20:03:11 Document 2 (similarity: 0.550584): "The American Motor Car Company was a short-lived company in the automotive industry founded in 1906 lasting until 1913. It was based in Indianapolis Indiana United States. The American Motor Car Company pioneered the underslung design." 2024/03/02 20:03:11 Asking LLM with augmented question... diff --git a/examples/rag-wikipedia-ollama/main.go b/examples/rag-wikipedia-ollama/main.go index 263f091..4d451ae 100644 --- a/examples/rag-wikipedia-ollama/main.go +++ b/examples/rag-wikipedia-ollama/main.go @@ -8,6 +8,7 @@ import ( "os" "runtime" "strconv" + "time" "github.com/philippgille/chromem-go" ) @@ -97,11 +98,13 @@ func main() { // on your needs and the supported context size of the LLM you use. // You can limit the search by filtering on content or metadata (like the article's // category), but we don't do that in this example. + start := time.Now() log.Println("Querying chromem-go...") docRes, err := collection.Query(ctx, question, 2, nil, nil) if err != nil { panic(err) } + log.Println("Search took", time.Since(start)) // Here you could filter out any documents whose similarity is below a certain threshold. // if docRes[...].Similarity < 0.5 { ... @@ -126,6 +129,7 @@ func main() { 2024/03/02 20:02:34 Reading JSON lines... 2024/03/02 20:02:34 Adding documents to chromem-go, including creating their embeddings via Ollama API... 2024/03/02 20:03:11 Querying chromem-go... + 2024/03/02 20:03:11 Search took 231.672667ms 2024/03/02 20:03:11 Document 1 (similarity: 0.723627): "Malleable Iron Range Company was a company that existed from 1896 to 1985 and primarily produced kitchen ranges made of malleable iron but also produced a variety of other related products. The company's primary trademark was 'Monarch' and was colloquially often referred to as the Monarch Company or just Monarch." 2024/03/02 20:03:11 Document 2 (similarity: 0.550584): "The American Motor Car Company was a short-lived company in the automotive industry founded in 1906 lasting until 1913. It was based in Indianapolis Indiana United States. The American Motor Car Company pioneered the underslung design." 2024/03/02 20:03:11 Asking LLM with augmented question... diff --git a/examples/semantic-search-arxiv-openai/README.md b/examples/semantic-search-arxiv-openai/README.md index 632a29e..1292fcf 100644 --- a/examples/semantic-search-arxiv-openai/README.md +++ b/examples/semantic-search-arxiv-openai/README.md @@ -27,6 +27,7 @@ The output can differ slightly on each run, but it's along the lines of: 2024/03/10 18:23:55 Read and parsed 5006 documents. 2024/03/10 18:23:55 Adding documents to chromem-go, including creating their embeddings via OpenAI API... 2024/03/10 18:28:12 Querying chromem-go... + 2024/03/10 18:28:12 Search took 529.451163ms 2024/03/10 18:28:12 Search results: 1) Similarity 0.488895: URL: https://arxiv.org/abs/2209.15469 diff --git a/examples/semantic-search-arxiv-openai/main.go b/examples/semantic-search-arxiv-openai/main.go index 508dbc4..e0d341b 100644 --- a/examples/semantic-search-arxiv-openai/main.go +++ b/examples/semantic-search-arxiv-openai/main.go @@ -9,6 +9,7 @@ import ( "os" "runtime" "strings" + "time" "github.com/philippgille/chromem-go" ) @@ -87,10 +88,12 @@ func main() { // You can limit the search by filtering on content or metadata (like the paper's // submitter), but we don't do that in this example. log.Println("Querying chromem-go...") + start := time.Now() docRes, err := collection.Query(ctx, searchTerm, 10, nil, nil) if err != nil { panic(err) } + log.Println("Search took", time.Since(start)) // Here you could filter out any documents whose similarity is below a certain threshold. // if docRes[...].Similarity < 0.5 { ... @@ -114,6 +117,7 @@ func main() { 2024/03/10 18:23:55 Read and parsed 5006 documents. 2024/03/10 18:23:55 Adding documents to chromem-go, including creating their embeddings via OpenAI API... 2024/03/10 18:28:12 Querying chromem-go... + 2024/03/10 18:28:12 Search took 529.451163ms 2024/03/10 18:28:12 Search results: 1) Similarity 0.488895: URL: https://arxiv.org/abs/2209.15469