Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
docs: embedding models
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Jul 17, 2024
1 parent 2e6764d commit 0c4e603
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ go.work
.vscode/

# Env
.env
*.env

knowledge/

Expand Down
47 changes: 47 additions & 0 deletions docs/docs/04-embedding_models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Embedding Models
---

# Embedding Models

## Generate Embeddings

Embeddings are automatically generated when ingesting a document.
Currently, this is part of the job of the vector store implementation (chromem-go).


## Choosing an Embedding Model

At the moment, knowledge only support OpenAI API compatible model provider endpoints, which you can configure using the following environment variables:

| Variable | Default | Notes |
|--------------------------|-----------------------------|---------------------------------------|
| `OPENAI_BASE_URL` | `https://api.openai.com/v1` | --- |
| `OPENAI_API_KEY` | `sk-foo` | -!- |
| `OPENAI_EMBEDDING_MODEL` | `text-embedding-ada-002` | --- |
| `OPENAI_API_VERSION` | `2024-02-01` | for Azure |
| `OPENAI_API_TYPE` | `OPEN_AI` | one of `OPEN_AI`, `AZURE`, `AZURE_AD` |

As you can see above, knowledge defaults to the `text-embedding-ada-002` model from OpenAI.
[Below](#example-configurations) you can see how to configure some other providers/models.

### Example Configurations

Here are some example configurations that we tested with the knowledge tool to confirm that they're working as expected.
This is no judgement on the quality of the models or how well they work with the knowledge tool in terms of retrieval accuracy.

<details>
<summary id="example-configurations-lm-studio"><strong>LM-Studio</strong></summary>

LM-Studio failed to return any embeddings if requested concurrently, so we set the parallel threads to 1.
This may change in the future. Tested with LM-Studio v0.2.27.


```dotenv
export OPENAI_BASE_URL=http://localhost:1234/v1
export OPENAI_API_KEY=lm-studio
export OPENAI_EMBEDDING_MODEL="CompendiumLabs/bge-large-en-v1.5-gguf"
export VS_CHROMEM_EMBEDDING_PARALLEL_THREAD="1"
```

</details>
6 changes: 6 additions & 0 deletions lmstudio.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export GIN_MODE=debug
export DEBUG=true
export OPENAI_BASE_URL=http://localhost:1234/v1
export OPENAI_API_KEY=lm-studio
export OPENAI_EMBEDDING_MODEL="CompendiumLabs/bge-large-en-v1.5-gguf"
export VS_CHROMEM_EMBEDDING_PARALLEL_THREAD="1"
4 changes: 3 additions & 1 deletion pkg/vectorstore/chromem/chromem.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func (s *Store) AddDocuments(ctx context.Context, docs []vs.Document, collection
return nil, fmt.Errorf("%w: %q", errors.ErrCollectionNotFound, collection)
}

err := col.AddDocuments(ctx, chromemDocs, env.GetIntFromEnvOrDefault(VsChromemEmbeddingParallelThread, 100))
concurrency := env.GetIntFromEnvOrDefault(VsChromemEmbeddingParallelThread, 100)
slog.Debug("Adding documents to collection", "collection", collection, "numDocuments", len(chromemDocs), "concurrency", concurrency)
err := col.AddDocuments(ctx, chromemDocs, concurrency)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0c4e603

Please sign in to comment.