Skip to content

Commit 6f1ba73

Browse files
shanghaikidclaude
andcommitted
docs: add CLAUDE.md for Claude Code guidance
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 034cf00 commit 6f1ba73

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Node.js SDK for [Milvus](https://milvus.io/) vector database, published as `@zilliz/milvus2-sdk-node`. Requires Node.js v18+.
8+
9+
## Commands
10+
11+
```bash
12+
# Install dependencies
13+
yarn install
14+
15+
# Build (cleans dist/, compiles TS, generates sdk.json)
16+
yarn build
17+
18+
# Run all tests (requires running Milvus instance)
19+
yarn test
20+
21+
# Run a single test file (NODE_ENV=dev is required)
22+
NODE_ENV=dev npx jest test/grpc/SomeTest.spec.ts
23+
24+
# Test coverage
25+
yarn coverage
26+
27+
# Format code
28+
npx prettier --write <file-or-directory>
29+
30+
# Regenerate proto JSON (after proto/ submodule update)
31+
yarn proto:json
32+
33+
# Initialize proto submodule
34+
git submodule update --init --recursive
35+
```
36+
37+
## Architecture
38+
39+
Source code lives in `milvus/` (not `src/`). Build output goes to `dist/`.
40+
41+
### Two Transport Layers
42+
43+
1. **gRPC** (`MilvusClient`) — primary transport with connection pooling, automatic retries, and interceptors
44+
2. **HTTP** (`HttpClient`) — REST alternative for environments where gRPC isn't available
45+
46+
### Class Inheritance Chain (gRPC)
47+
48+
```
49+
BaseClient (proto loading, TLS, auth)
50+
→ User (user/role management)
51+
→ Database (database operations)
52+
→ Collection (collection CRUD)
53+
→ Data (insert/upsert/delete/query/search)
54+
→ Partition (partition management)
55+
→ MilvusIndex (index operations)
56+
→ Resource (resource queries)
57+
→ GRPCClient (channel pool, service init)
58+
→ MilvusClient (high-level API)
59+
```
60+
61+
Each class in `milvus/grpc/` adds one domain of Milvus operations. `MilvusClient` in `milvus/MilvusClient.ts` is the public entry point that extends `GRPCClient` with simplified high-level methods (aligned with the Python SDK).
62+
63+
### Directory Layout
64+
65+
- `milvus/grpc/` — gRPC client classes (one per domain: Collection, Data, User, etc.)
66+
- `milvus/http/` — HTTP client implementation
67+
- `milvus/types/` — TypeScript type definitions for requests/responses
68+
- `milvus/const/` — Constants, defaults, error codes
69+
- `milvus/utils/` — Utilities (schema building, data formatting, gRPC helpers, validation)
70+
- `milvus/proto-json/` — Generated proto definitions (from `yarn proto:json`)
71+
- `proto/` — Git submodule with upstream Milvus `.proto` files
72+
- `test/grpc/`, `test/http/`, `test/utils/` — Tests organized by transport/domain
73+
- `test/tools/` — Test helpers (collection param generators, data generators)
74+
75+
### Key Patterns
76+
77+
**Adding a new gRPC API method:**
78+
1. If proto has been updated: sync submodule (`git submodule update --init --recursive`) then regenerate JSON (`yarn proto:json`)
79+
2. Define request/response types in `milvus/types/`
80+
3. Implement method in the appropriate `milvus/grpc/` class
81+
4. Wrap gRPC calls with `promisify(this.grpcClient.methodName.bind(this.grpcClient), metadata, timeout)`
82+
5. Check results against `ErrorCode.SUCCESS`
83+
6. Add tests in `test/grpc/`
84+
7. Add JSDoc for public methods (include `@param` and `@returns`)
85+
86+
**Error handling:**
87+
```typescript
88+
if (res.error_code !== ErrorCode.SUCCESS) {
89+
throw new Error(res.reason);
90+
}
91+
```
92+
93+
**gRPC interceptors** (in `milvus/utils/Grpc.ts`): meta (auth/db_name), retry (exponential backoff), trace (OpenTelemetry), request metadata (timing).
94+
95+
**Connection pooling:** Uses `generic-pool` with configurable min/max (defaults: 5/10).
96+
97+
## Code Style
98+
99+
- TypeScript strict mode, target ES2015, CommonJS modules
100+
- Prettier: 2 spaces, single quotes, semicolons, ES5 trailing commas, avoid arrow parens
101+
- Classes: PascalCase; methods/variables: camelCase; constants: UPPER_CASE
102+
- Test files: `*.spec.ts`
103+
- Tests use `describe`/`it` blocks with `beforeAll`/`afterAll` for setup/cleanup
104+
- Tests are integration tests that connect to a real Milvus instance

0 commit comments

Comments
 (0)