Rust implementations of the book A Common Sense Guide to AI Engineering published by Pragmatic Programmers.
All examples expect the OPENAI_API_KEY to be exported as an environment variable, e.g.,
$ OPENAI_API_KEY=<api-key> cargo run -p hello-world -- ...As this repo uses Cargo workspace to organize the demonstrates, each demo's source directory
name has the book's chapter prefix, e.g., 01-hello-world is the demo from chapter 1.
However, when running the demo, drop the chapter prefix when the package -p (as shown above).
- Chapter 1: HeLLMo, World!
- Chapter 5: Building a Chatbot
- Chapter 6: Augmenting a Prompt with Knowledge
- Chapter 7: Efficiently Adding Knowledge with RAG
- Chapter 8: Measuring Quality with Evals
- Setting Up Our App
- Generating Traces: reuses implementation from [Setting Up Our App][eval-chatbot] for simplification
- Chapter 10: Reducing Hallucinations
- [Reducing Hallucinations][10-reduce_hallucinations]: reuses implementation from Setting Up Our App for simplification
- Chapter 11: Evaluating and Optimizing RAG
- Expanding the Query: reuses implementation from [Reducing Hallucinations][10-reduce_hallucinations] for simplication
Other than the language and the libraries used, this port:
- Uses embedded LanceDB instead of Pinecone for simplicity, i.e., no need to sign up Pinecone; also uses fastembed for text embedding.
- Supports interfacing with local LLM servers, such as LM Studio and Ollama.
The following table shows the crates used in place of the wheels:
| Wheel | Crate | Remarks |
|---|---|---|
| Docling | Transmutation | Augmented with reqwest to retrieve resources from the web |
| openai | async-openai | |
| - | lancedb | Replaced Pinecone as vector database |
| - | fastembed | Generate text embeddings when populating vector database |
As LanceDB uses ProtoBuf, you may need to install protobuf using Homebrew:
brew install protobufOr using asdf-vm:
asdf plugin add protoc https://github.com/paxosglobal/asdf-protoc.gitFor convenience, all the files in resources directory are copied from the
book's source code; the copyright of those files belong to the book's author and
the publisher.