Skip to content

Commit

Permalink
Add query performance to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
philippgille committed Mar 10, 2024
1 parent c16b7d9 commit acbe5d2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/rag-wikipedia-ollama/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
4 changes: 4 additions & 0 deletions examples/rag-wikipedia-ollama/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"runtime"
"strconv"
"time"

"github.com/philippgille/chromem-go"
)
Expand Down Expand Up @@ -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 { ...

Expand All @@ -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...
Expand Down
1 change: 1 addition & 0 deletions examples/semantic-search-arxiv-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/semantic-search-arxiv-openai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"runtime"
"strings"
"time"

"github.com/philippgille/chromem-go"
)
Expand Down Expand Up @@ -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 { ...

Expand All @@ -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
Expand Down

0 comments on commit acbe5d2

Please sign in to comment.