Skip to content

Commit f942a68

Browse files
elibengopherbot
authored andcommitted
ragserver: start adding new example of a RAG server in Go
Change-Id: I256449c9cd97ef53251e326d943858c237b4ea16 Reviewed-on: https://go-review.googlesource.com/c/example/+/608055 Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Eli Bendersky <[email protected]> TryBot-Bypass: Eli Bendersky <[email protected]> Reviewed-by: Eli Bendersky <[email protected]>
1 parent 39e772f commit f942a68

11 files changed

+884
-0
lines changed

ragserver/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ragserver
2+
3+
*RAG stands for Retrieval Augmented Generation*
4+
5+
Demos of implementing a "RAG Server" in Go, using [Google
6+
AI](https://ai.google.dev/) for embeddings and language models and
7+
[Weaviate](https://weaviate.io/) as a vector database.
8+
9+
10+
## How it works
11+
12+
The server we're developing is a standard Go HTTP server, listening on a local
13+
port. See the next section for the request schema for this server. It supports
14+
adding new documents to its context, and getting queries that would use this
15+
context.
16+
17+
Weaviate has the be installed locally; the easiest way to do so is by using
18+
`docker-compose` as described in the Usage section.
19+
20+
## Server request schema
21+
22+
```
23+
/add/: POST {"documents": [{"text": "..."}, {"text": "..."}, ...]}
24+
response: OK (no body)
25+
26+
/query/: GET {"content": "..."}
27+
response: model response as a string
28+
```
29+
30+
## Server variants
31+
32+
* `ragserver`: uses the Google AI Go SDK directly for LLM calls and embeddings,
33+
and the Weaviate Go client library directly for interacting with Weaviate.
34+
35+
## Usage
36+
37+
* In terminal window 1, `cd tests` and run `docker-compose up`;
38+
This will start the weaviate service in the foreground.
39+
* In terminal window 2, run `GEMINI_API_KEY=... go run .` in the tested
40+
`ragserver` directory.
41+
* In terminal window 3, we can now run scripts to clear/populate the
42+
weaviate DB and interact with `ragserver`. The following instructions are
43+
for terminal window 3.
44+
45+
Run `cd tests`; then we can clear out the weaviate DB with
46+
`./weaviate-delete-objects.sh`. To add documents to the DB through `ragserver`,
47+
run `./add-documents.sh`. For a sample query, run `./query.sh`
48+
Adjust the contents of these scripts as needed.
49+
50+
## Environment variables
51+
52+
* `SERVERPORT`: the port this server is listening on (default 9020)
53+
* `WVPORT`: the port Weaviate is listening on (default 9035)
54+
* `GEMINI_API_KEY`: API key for the Gemini service at https://ai.google.dev

ragserver/ragserver/go.mod

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module golang.org/x/example/ragserver/ragserver
2+
3+
go 1.23.0
4+
5+
require (
6+
github.com/google/generative-ai-go v0.17.0
7+
github.com/weaviate/weaviate v1.26.1
8+
github.com/weaviate/weaviate-go-client/v4 v4.15.1
9+
google.golang.org/api v0.194.0
10+
)
11+
12+
require (
13+
cloud.google.com/go v0.115.1 // indirect
14+
cloud.google.com/go/ai v0.8.0 // indirect
15+
cloud.google.com/go/auth v0.9.1 // indirect
16+
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
17+
cloud.google.com/go/compute/metadata v0.5.0 // indirect
18+
cloud.google.com/go/longrunning v0.5.7 // indirect
19+
github.com/PuerkitoBio/purell v1.1.1 // indirect
20+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
21+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
22+
github.com/felixge/httpsnoop v1.0.4 // indirect
23+
github.com/go-logr/logr v1.4.2 // indirect
24+
github.com/go-logr/stdr v1.2.2 // indirect
25+
github.com/go-openapi/analysis v0.21.2 // indirect
26+
github.com/go-openapi/errors v0.22.0 // indirect
27+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
28+
github.com/go-openapi/jsonreference v0.19.6 // indirect
29+
github.com/go-openapi/loads v0.21.1 // indirect
30+
github.com/go-openapi/spec v0.20.4 // indirect
31+
github.com/go-openapi/strfmt v0.23.0 // indirect
32+
github.com/go-openapi/swag v0.22.3 // indirect
33+
github.com/go-openapi/validate v0.21.0 // indirect
34+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
35+
github.com/google/s2a-go v0.1.8 // indirect
36+
github.com/google/uuid v1.6.0 // indirect
37+
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
38+
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
39+
github.com/josharian/intern v1.0.0 // indirect
40+
github.com/mailru/easyjson v0.7.7 // indirect
41+
github.com/mitchellh/mapstructure v1.5.0 // indirect
42+
github.com/oklog/ulid v1.3.1 // indirect
43+
github.com/pkg/errors v0.9.1 // indirect
44+
go.mongodb.org/mongo-driver v1.14.0 // indirect
45+
go.opencensus.io v0.24.0 // indirect
46+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 // indirect
47+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
48+
go.opentelemetry.io/otel v1.26.0 // indirect
49+
go.opentelemetry.io/otel/metric v1.26.0 // indirect
50+
go.opentelemetry.io/otel/trace v1.26.0 // indirect
51+
golang.org/x/crypto v0.26.0 // indirect
52+
golang.org/x/net v0.28.0 // indirect
53+
golang.org/x/oauth2 v0.22.0 // indirect
54+
golang.org/x/sync v0.8.0 // indirect
55+
golang.org/x/sys v0.24.0 // indirect
56+
golang.org/x/text v0.17.0 // indirect
57+
golang.org/x/time v0.6.0 // indirect
58+
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f // indirect
59+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
60+
google.golang.org/grpc v1.65.0 // indirect
61+
google.golang.org/protobuf v1.34.2 // indirect
62+
gopkg.in/yaml.v3 v3.0.1 // indirect
63+
)

0 commit comments

Comments
 (0)