Repository navigation
feat: add RAG search tool with Weaviate backend - #73
Conversation
Signed-off-by: Pavel Anni <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
Adds rag_search tool that wraps rag.Client for use in agentic loops. The tool accepts query and optional limit, returns formatted chunks with scores. Follows the existing tool pattern (readfile, exec). Tests: - Tool name and parameters schema - Execute with mock RAG client - Missing query validation - Default/max limit enforcement - Client error propagation - No results case All 7 tests pass. Signed-off-by: Pavel Anni <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
…prove test assertions Signed-off-by: Pavel Anni <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
Makes seed.sh container-runtime agnostic (works with Docker, Podman, or any setup where Ollama is reachable via HTTP). Signed-off-by: Pavel Anni <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis PR adds RAG (Retrieval-Augmented Generation) support to DocsClaw using Weaviate as the vector database backend. The changes introduce a new ChangesWeaviate RAG Integration for DocsClaw
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- Use jq for JSON construction in seed.sh to prevent escaping bugs - Return error on unexpected Weaviate response shape instead of silent nil - Add explicit validation for empty backend config - Document cosine distance assumption on Chunk.Score - Assert default limit value in test - Update design doc to match actual seed.sh implementation - Replace python3 dependency with jq in seed.sh Signed-off-by: Pavel Anni <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 8
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/dev/2026-05-15-rag-feature.md`:
- Around line 224-228: The two unlabeled fenced code blocks (the explanatory
paragraph block and the example result block referenced at lines 224 and 249)
are triggering markdownlint MD040; update each opening fence from ``` to ```text
so both blocks are explicitly labeled as text (i.e., change the fence before
"Search the document store..." and the fence before "[1] (score: 0.91)..." to
use ```text).
- Around line 67-84: Update the docs to reflect the shipped RAG implementation:
remove the go get instruction for github.com/weaviate/weaviate-go-client/v5 and
replace the SDK-based example (pkg/rag/weaviate.go and pkg/tools/rag_search.go)
with guidance that the project uses raw HTTP/GraphQL requests implemented in
internal/ragsearch/ragsearch.go; describe the HTTP/GraphQL approach and
reference the internal/ragsearch/ragsearch.go tool and its exposed
functions/methods when explaining how to perform searches instead of referencing
weaviate-go-client types like weaviate.Client or graphql.Query.
In `@internal/ragsearch/ragsearch.go`:
- Around line 47-55: Trim and validate the query string (use strings.TrimSpace
on args["query"] and treat whitespace-only as empty) and return
tools.Errorf("query is required") if it's empty; for limit, normalize multiple
numeric types instead of only float64 by handling int, int64, float32, float64
and json.Number (or string) via a type switch on args["limit"], convert to int,
enforce >0 and fall back to t.config.DefaultLimit if missing/invalid, and ensure
fractional float64 values are converted with int(...) only after validating
positivity.
In `@pkg/rag/config.go`:
- Around line 26-30: The constructor NewClient currently dereferences
cfg.Backend before checking cfg for nil; add an explicit nil check at the start
of NewClient to return a typed error (e.g., fmt.Errorf("rag: config is
required")) when cfg == nil, then proceed to validate cfg.Backend and call
cfg.ApplyDefaults(); reference the NewClient function and the
Config.ApplyDefaults method when making this change so callers get a clear,
non-panic error for nil configs.
In `@pkg/rag/weaviate.go`:
- Around line 105-116: The code currently coerces a missing/invalid
_additional["distance"] to 0 causing Score=1; in the weaviate query parsing
(where you read obj[w.textField], additional := obj["_additional"], id,
distance) explicitly check that additional["distance"] exists and type-asserts
to float64 (or convertible numeric) before computing Score; if the distance is
missing/invalid, do not set Score to 1 — instead skip that result (or omit
appending the Chunk) or handle it via a clear fallback (e.g., continue) so bad
records aren’t ranked as top hits; update the Chunk creation logic around
distance, id, and Score accordingly.
- Around line 21-34: NewWeaviateClient currently allows an empty textField which
later causes silent failures when extracting chunks; update NewWeaviateClient to
validate textField and either return an error if it's empty or assign a sensible
default before constructing WeaviateClient. Specifically, in NewWeaviateClient
check the textField parameter (in addition to baseURL and collection) and if
empty either return fmt.Errorf("weaviate: textField is required") or set
textField = "<default_field_name>" (pick a canonical field used elsewhere)
before returning the &WeaviateClient{...}; ensure the unique symbol
NewWeaviateClient and struct fields textField, baseURL, collection are updated
accordingly.
In `@testdata/rag/README.md`:
- Around line 49-63: The fenced code blocks in the README sample outputs are
missing a language token which triggers markdownlint MD040; update each
triple-backtick fence for the example output blocks (the large CLI/output
snippets shown in the README) to include a language token such as text (i.e.
change ``` to ```text) so all code fences (including the CLI pull/ingest/verify
blocks and similar examples) are labeled; ensure you update every occurrence
noted in the review (the large sample output blocks) so MD040 warnings are
resolved.
In `@testdata/rag/seed.sh`:
- Around line 4-5: The script defines OLLAMA_URL but later hard-codes
"http://ollama:11434" when calling Ollama; update those occurrences to use the
configured variable (e.g., replace the literal URL with "${OLLAMA_URL}" or
"$OLLAMA_URL") so all uses in seed.sh (including the section around the Ollama
calls referenced) honor the environment override; ensure quoting is preserved
when interpolating into curl/HTTP calls and remove any remaining hard-coded
"http://ollama:11434" strings.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: f9ca9251-a4ac-4011-97b7-25693859a77e
📒 Files selected for processing (14)
docs/dev/2026-05-15-rag-feature.mdinternal/cmd/agentconfig.gointernal/cmd/serve.gointernal/ragsearch/ragsearch.gointernal/ragsearch/ragsearch_test.gopkg/rag/config.gopkg/rag/config_test.gopkg/rag/rag.gopkg/rag/weaviate.gopkg/rag/weaviate_test.gotestdata/rag/README.mdtestdata/rag/docker-compose.yamltestdata/rag/seed.shtestdata/standalone/agent-config.yaml
| func NewWeaviateClient(baseURL, collection, textField string) (*WeaviateClient, error) { | ||
| baseURL = strings.TrimRight(baseURL, "/") | ||
| if baseURL == "" { | ||
| return nil, fmt.Errorf("weaviate: base URL is required") | ||
| } | ||
| if collection == "" { | ||
| return nil, fmt.Errorf("weaviate: collection is required") | ||
| } | ||
| return &WeaviateClient{ | ||
| baseURL: baseURL, | ||
| collection: collection, | ||
| textField: textField, | ||
| httpClient: &http.Client{Timeout: 30 * time.Second}, | ||
| }, nil |
There was a problem hiding this comment.
Reject or default empty textField in constructor.
Line 32 accepts an empty textField, which later makes chunk extraction silently fail (obj[""]) and returns blank texts.
Proposed fix
func NewWeaviateClient(baseURL, collection, textField string) (*WeaviateClient, error) {
baseURL = strings.TrimRight(baseURL, "/")
@@
if collection == "" {
return nil, fmt.Errorf("weaviate: collection is required")
}
+ if strings.TrimSpace(textField) == "" {
+ textField = "content"
+ }
return &WeaviateClient{🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/rag/weaviate.go` around lines 21 - 34, NewWeaviateClient currently allows
an empty textField which later causes silent failures when extracting chunks;
update NewWeaviateClient to validate textField and either return an error if
it's empty or assign a sensible default before constructing WeaviateClient.
Specifically, in NewWeaviateClient check the textField parameter (in addition to
baseURL and collection) and if empty either return fmt.Errorf("weaviate:
textField is required") or set textField = "<default_field_name>" (pick a
canonical field used elsewhere) before returning the &WeaviateClient{...};
ensure the unique symbol NewWeaviateClient and struct fields textField, baseURL,
collection are updated accordingly.
| ``` | ||
| ==> Pulling embedding model (first run only, ~274 MB)... | ||
| pulling manifest... pulling sha256:... success | ||
| ==> Creating Docs collection... | ||
| Collection created. | ||
| ==> Ingesting sample documents... | ||
| [1/8] ingested | ||
| ... | ||
| ==> Ingested 8 documents into Docs collection | ||
| ==> Verifying search... | ||
| { | ||
| "data": { ... ranked results ... } | ||
| } | ||
| ==> Done. Weaviate is ready for DocsClaw. | ||
| ``` |
There was a problem hiding this comment.
Label fenced code blocks with a language to satisfy markdownlint.
At Line 49, Line 107, and Line 132, add fence languages (for example text) to clear MD040 warnings.
Also applies to: 107-119, 132-134
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 49-49: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@testdata/rag/README.md` around lines 49 - 63, The fenced code blocks in the
README sample outputs are missing a language token which triggers markdownlint
MD040; update each triple-backtick fence for the example output blocks (the
large CLI/output snippets shown in the README) to include a language token such
as text (i.e. change ``` to ```text) so all code fences (including the CLI
pull/ingest/verify blocks and similar examples) are labeled; ensure you update
every occurrence noted in the review (the large sample output blocks) so MD040
warnings are resolved.
| WEAVIATE_URL="${WEAVIATE_URL:-http://localhost:8080}" | ||
| OLLAMA_URL="${OLLAMA_URL:-http://localhost:11434}" |
There was a problem hiding this comment.
Schema creation ignores configurable Ollama endpoint.
OLLAMA_URL is configurable, but Line 31 hard-codes http://ollama:11434. This can break seeding outside the default compose network.
Suggested fix
WEAVIATE_URL="${WEAVIATE_URL:-http://localhost:8080}"
OLLAMA_URL="${OLLAMA_URL:-http://localhost:11434}"
+WEAVIATE_OLLAMA_API_ENDPOINT="${WEAVIATE_OLLAMA_API_ENDPOINT:-http://ollama:11434}"
@@
- -d '{
+ -d "{
\"class\": \"Docs\",
\"vectorizer\": \"text2vec-ollama\",
\"moduleConfig\": {
\"text2vec-ollama\": {
- \"apiEndpoint\": \"http://ollama:11434\",
+ \"apiEndpoint\": \"${WEAVIATE_OLLAMA_API_ENDPOINT}\",
\"model\": \"nomic-embed-text\"
}
},
@@
- }')
+ }")Also applies to: 29-33
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@testdata/rag/seed.sh` around lines 4 - 5, The script defines OLLAMA_URL but
later hard-codes "http://ollama:11434" when calling Ollama; update those
occurrences to use the configured variable (e.g., replace the literal URL with
"${OLLAMA_URL}" or "$OLLAMA_URL") so all uses in seed.sh (including the section
around the Ollama calls referenced) honor the environment override; ensure
quoting is preserved when interpolating into curl/HTTP calls and remove any
remaining hard-coded "http://ollama:11434" strings.
- Trim whitespace-only queries in rag_search tool - Add nil config guard in NewClient - Skip chunks with missing distance instead of ranking as score=1 - Replace SDK code in design doc with HTTP/GraphQL implementation note - Add text labels to unlabeled markdown code fences (MD040) Signed-off-by: Pavel Anni <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
Summary
rag_searchtool that retrieves semantically similar document chunks from a Weaviate vector databasenet/http) instead of the Weaviate SDK — zero new dependencies, keeping the binary leanrag.Clientinterface with aSearchmethod, making future backend connectors (Milvus, pgvector) drop-in additionsrag:block inagent-config.yaml— if absent, no tool is registered; if present, the tool is auto-availableDesign
pkg/rag/rag.goClientinterface +Chunktypepkg/rag/config.goConfigstruct, defaults, factorypkg/rag/weaviate.gointernal/ragsearch/rag_searchtool (implementstools.Tool)internal/cmd/serve.goRegisterAlwaysAllowedtestdata/rag/Config example
Test plan
pkg/rag/, 7 ininternal/ragsearch/)rag_searchand synthesizes answers from retrieved chunksgo test ./...passes,golangci-lintclean on changed packagesdocs/dev/2026-05-15-rag-feature.md)Design doc
docs/dev/2026-05-15-rag-feature.md— includes Kubernetes manifests, Helm chart options, and OpenShift-specific notes for future deployment.Summary by CodeRabbit
Release Notes
New Features
rag_searchtool available when configured with Weaviate backend supportDocumentation