@ia-ccun/code-agent-cli 0.0.52 → 0.0.54-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/config/agent/bin/README.md +102 -0
  2. package/config/agent/bin/fd.exe +0 -0
  3. package/config/agent/bin/rg.exe +0 -0
  4. package/config/agent/extensions/aicode-advisor.ts +13 -0
  5. package/config/agent/extensions/aicode-btw.ts +66 -14
  6. package/config/agent/extensions/aicode-cd.ts +834 -0
  7. package/config/agent/extensions/aicode-filter-outputs.ts +131 -0
  8. package/config/agent/extensions/aicode-grillMe.ts +198 -0
  9. package/config/agent/extensions/aicode-pets.ts +362 -0
  10. package/config/agent/extensions/aicode-safety-guard.ts +552 -0
  11. package/config/agent/extensions/aicode-snake.ts +354 -0
  12. package/config/agent/extensions/aicode-tips.ts +70 -16
  13. package/config/agent/extensions/aicode-todo-progress.ts +547 -0
  14. package/config/agent/extensions/custom.ts +93 -95
  15. package/config/agent/extensions/error-monitor.ts +1 -18
  16. package/config/agent/extensions/ponytail.ts +441 -0
  17. package/config/agent/extensions/tps.ts +87 -0
  18. package/config/agent/extensions/working-msg.ts +165 -50
  19. package/config/agent/help.md +0 -7
  20. package/config/agent/models.json +7 -7
  21. package/config/agent/settings.json +16 -16
  22. package/config/agent/skills/chroma/LICENSE +21 -0
  23. package/config/agent/skills/chroma/chroma-local/SKILL.md +165 -0
  24. package/config/agent/skills/chroma/chroma-local/cli.md +48 -0
  25. package/config/agent/skills/chroma/chroma-local/data-model.md +103 -0
  26. package/config/agent/skills/chroma/chroma-local/error-handling/python.md +166 -0
  27. package/config/agent/skills/chroma/chroma-local/error-handling/typescript.md +231 -0
  28. package/config/agent/skills/chroma/chroma-local/local-chroma/python.md +95 -0
  29. package/config/agent/skills/chroma/chroma-local/local-chroma/typescript.md +101 -0
  30. package/config/agent/skills/chroma/chroma-local/metadata/python.md +154 -0
  31. package/config/agent/skills/chroma/chroma-local/metadata/typescript.md +153 -0
  32. package/config/agent/skills/chroma/chroma-local/querying/python.md +147 -0
  33. package/config/agent/skills/chroma/chroma-local/querying/typescript.md +157 -0
  34. package/config/agent/skills/chroma/chroma-local/regex/python.md +69 -0
  35. package/config/agent/skills/chroma/chroma-local/regex/typescript.md +71 -0
  36. package/config/agent/skills/chroma/chroma-local/understanding-a-codebase.md +80 -0
  37. package/config/agent/skills/chroma/chroma-local/updating-deleting/python.md +159 -0
  38. package/config/agent/skills/chroma/chroma-local/updating-deleting/typescript.md +228 -0
  39. package/config/agent/skills/hello/SKILL.md +1 -1
  40. package/config/agent/skills/ponytail/SKILL.md +100 -0
  41. package/config/agent/skills/ponytail-audit/SKILL.md +40 -0
  42. package/config/agent/skills/ponytail-debt/SKILL.md +44 -0
  43. package/config/agent/skills/ponytail-help/SKILL.md +68 -0
  44. package/config/agent/skills/ponytail-review/SKILL.md +56 -0
  45. package/config/agent/skills_bak/milvus-skill/LICENSE +202 -0
  46. package/config/agent/skills_bak/milvus-skill/README.md +37 -0
  47. package/config/agent/skills_bak/milvus-skill/SKILL.md +259 -0
  48. package/config/agent/skills_bak/milvus-skill/references/collection.md +86 -0
  49. package/config/agent/skills_bak/milvus-skill/references/database.md +24 -0
  50. package/config/agent/skills_bak/milvus-skill/references/index.md +69 -0
  51. package/config/agent/skills_bak/milvus-skill/references/partition.md +29 -0
  52. package/config/agent/skills_bak/milvus-skill/references/patterns.md +150 -0
  53. package/config/agent/skills_bak/milvus-skill/references/user-role.md +90 -0
  54. package/config/agent/skills_bak/milvus-skill/references/vector.md +247 -0
  55. package/config/agent/skills_bak/zread/README.md +115 -0
  56. package/config/agent/skills_bak/zread/SKILL.md +103 -0
  57. package/config/agent/skills_bak/zread/references/stdio-protocol.md +312 -0
  58. package/package.json +7 -6
  59. package/scripts/postinstall.js +58 -1
  60. package/config/agent/dangerous-patterns.json +0 -106
  61. package/config/agent/extensions/bash-check.ts +0 -227
  62. package/config/agent/skills/refactor/SKILL.md +0 -40
  63. /package/config/agent/{skills → skills_bak}/csv-data-summarizer/SKILL.md +0 -0
  64. /package/config/agent/{skills → skills_bak}/csv-data-summarizer/analyze.py +0 -0
  65. /package/config/agent/{skills → skills_bak}/csv-data-summarizer/examples/showcase_financial_pl_data.csv +0 -0
  66. /package/config/agent/{skills → skills_bak}/csv-data-summarizer/requirements.txt +0 -0
  67. /package/config/agent/{skills → skills_bak}/csv-data-summarizer/resources/sample.csv +0 -0
  68. /package/config/agent/{skills → skills_bak}/dispatching-parallel-agents/SKILL.md +0 -0
  69. /package/config/agent/{skills → skills_bak}/find-skills/SKILL.md +0 -0
  70. /package/config/agent/{skills → skills_bak}/finishing-a-development-branch/SKILL.md +0 -0
  71. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/LICENSE +0 -0
  72. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/README.md +0 -0
  73. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/README.zh.md +0 -0
  74. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/SKILL.md +0 -0
  75. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/agentloop-core.svg +0 -0
  76. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/agents/openai.yaml +0 -0
  77. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/assets/samples/sample-style1-flat.png +0 -0
  78. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/assets/samples/sample-style2-dark.png +0 -0
  79. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/assets/samples/sample-style3-blueprint.png +0 -0
  80. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/assets/samples/sample-style4-notion.png +0 -0
  81. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/assets/samples/sample-style5-glass.png +0 -0
  82. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/assets/samples/sample-style6-claude.png +0 -0
  83. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/assets/samples/sample-style7-openai.png +0 -0
  84. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/fixtures/agent-memory-types-style4.json +0 -0
  85. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/fixtures/api-flow-style7.json +0 -0
  86. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/fixtures/mem0-style1.json +0 -0
  87. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/fixtures/microservices-style3.json +0 -0
  88. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/fixtures/multi-agent-style5.json +0 -0
  89. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/fixtures/system-architecture-style6.json +0 -0
  90. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/fixtures/tool-call-style2.json +0 -0
  91. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/package.json +0 -0
  92. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/icons.md +0 -0
  93. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/style-1-flat-icon.md +0 -0
  94. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/style-2-dark-terminal.md +0 -0
  95. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/style-3-blueprint.md +0 -0
  96. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/style-4-notion-clean.md +0 -0
  97. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/style-5-glassmorphism.md +0 -0
  98. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/style-6-claude-official.md +0 -0
  99. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/style-7-openai.md +0 -0
  100. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/style-diagram-matrix.md +0 -0
  101. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/references/svg-layout-best-practices.md +0 -0
  102. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/scripts/README.md +0 -0
  103. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/scripts/generate-diagram.sh +0 -0
  104. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/scripts/generate-from-template.py +0 -0
  105. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/scripts/test-all-styles.sh +0 -0
  106. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/scripts/validate-svg.sh +0 -0
  107. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/agent-architecture.svg +0 -0
  108. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/architecture.svg +0 -0
  109. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/comparison-matrix.svg +0 -0
  110. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/data-flow.svg +0 -0
  111. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/er-diagram.svg +0 -0
  112. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/flowchart.svg +0 -0
  113. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/sequence.svg +0 -0
  114. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/state-machine.svg +0 -0
  115. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/timeline.svg +0 -0
  116. /package/config/agent/{skills → skills_bak}/fireworks-tech-graph/templates/use-case.svg +0 -0
  117. /package/config/agent/{skills → skills_bak}/librarian/SKILL.md +0 -0
  118. /package/config/agent/{skills → skills_bak}/markdown-to-html/SKILL.md +0 -0
  119. /package/config/agent/{skills → skills_bak}/pr/SKILL.md +0 -0
  120. /package/config/agent/{skills → skills_bak}/receiving-code-review/SKILL.md +0 -0
  121. /package/config/agent/{skills → skills_bak}/requesting-code-review/SKILL.md +0 -0
  122. /package/config/agent/{skills → skills_bak}/requesting-code-review/code-reviewer.md +0 -0
  123. /package/config/agent/{skills → skills_bak}/subagent-driven-development/SKILL.md +0 -0
  124. /package/config/agent/{skills → skills_bak}/subagent-driven-development/code-quality-reviewer-prompt.md +0 -0
  125. /package/config/agent/{skills → skills_bak}/subagent-driven-development/implementer-prompt.md +0 -0
  126. /package/config/agent/{skills → skills_bak}/subagent-driven-development/spec-reviewer-prompt.md +0 -0
  127. /package/config/agent/{skills → skills_bak}/systematic-debugging/CREATION-LOG.md +0 -0
  128. /package/config/agent/{skills → skills_bak}/systematic-debugging/SKILL.md +0 -0
  129. /package/config/agent/{skills → skills_bak}/systematic-debugging/condition-based-waiting-example.ts +0 -0
  130. /package/config/agent/{skills → skills_bak}/systematic-debugging/condition-based-waiting.md +0 -0
  131. /package/config/agent/{skills → skills_bak}/systematic-debugging/defense-in-depth.md +0 -0
  132. /package/config/agent/{skills → skills_bak}/systematic-debugging/find-polluter.sh +0 -0
  133. /package/config/agent/{skills → skills_bak}/systematic-debugging/root-cause-tracing.md +0 -0
  134. /package/config/agent/{skills → skills_bak}/systematic-debugging/test-academic.md +0 -0
  135. /package/config/agent/{skills → skills_bak}/systematic-debugging/test-pressure-1.md +0 -0
  136. /package/config/agent/{skills → skills_bak}/systematic-debugging/test-pressure-2.md +0 -0
  137. /package/config/agent/{skills → skills_bak}/systematic-debugging/test-pressure-3.md +0 -0
  138. /package/config/agent/{skills → skills_bak}/test-driven-development/SKILL.md +0 -0
  139. /package/config/agent/{skills → skills_bak}/test-driven-development/testing-anti-patterns.md +0 -0
  140. /package/config/agent/{skills → skills_bak}/unit-test/SKILL.md +0 -0
  141. /package/config/agent/{skills → skills_bak}/using-git-worktrees/SKILL.md +0 -0
@@ -0,0 +1,86 @@
1
+ # Collection Management — Detailed Reference
2
+
3
+ ## Supported Data Types
4
+
5
+ ### Scalar Types
6
+
7
+ | DataType | Notes |
8
+ |----------|-------|
9
+ | `DataType.BOOL` | Boolean |
10
+ | `DataType.INT8` / `INT16` / `INT32` / `INT64` | Integers |
11
+ | `DataType.FLOAT` / `DOUBLE` | Floating point |
12
+ | `DataType.VARCHAR` | String (requires `max_length`) |
13
+ | `DataType.JSON` | JSON object |
14
+ | `DataType.ARRAY` | Array (requires `element_type`, `max_capacity`) |
15
+
16
+ ### Vector Types
17
+
18
+ | DataType | Notes |
19
+ |----------|-------|
20
+ | `DataType.FLOAT_VECTOR` | Float32 vector (requires `dim`) |
21
+ | `DataType.FLOAT16_VECTOR` | Float16 vector (requires `dim`) |
22
+ | `DataType.BFLOAT16_VECTOR` | BFloat16 vector (requires `dim`) |
23
+ | `DataType.BINARY_VECTOR` | Binary vector (requires `dim`) |
24
+ | `DataType.SPARSE_FLOAT_VECTOR` | Sparse vector (no `dim` needed) |
25
+ | `DataType.INT8_VECTOR` | Int8 vector (requires `dim`) |
26
+
27
+ ## add_field Parameters
28
+
29
+ ```python
30
+ schema.add_field(
31
+ field_name="my_field",
32
+ datatype=DataType.VARCHAR,
33
+ is_primary=False,
34
+ auto_id=False,
35
+ max_length=256, # Required for VARCHAR
36
+ dim=768, # Required for vector types (except sparse)
37
+ element_type=DataType.INT64, # Required for ARRAY
38
+ max_capacity=100, # Required for ARRAY
39
+ nullable=False,
40
+ default_value=None,
41
+ is_partition_key=False,
42
+ description=""
43
+ )
44
+ ```
45
+
46
+ ## All Collection Operations
47
+
48
+ ```python
49
+ # List all collections
50
+ collections = client.list_collections()
51
+
52
+ # Describe a collection
53
+ info = client.describe_collection(collection_name="my_collection")
54
+
55
+ # Check if collection exists
56
+ exists = client.has_collection(collection_name="my_collection")
57
+
58
+ # Rename a collection
59
+ client.rename_collection(old_name="old_name", new_name="new_name")
60
+
61
+ # Drop a collection
62
+ client.drop_collection(collection_name="my_collection")
63
+
64
+ # Truncate a collection (delete all data, keep schema and index)
65
+ client.truncate_collection(collection_name="my_collection")
66
+
67
+ # Load collection into memory (required before search/query)
68
+ client.load_collection(collection_name="my_collection")
69
+
70
+ # Release collection from memory
71
+ client.release_collection(collection_name="my_collection")
72
+
73
+ # Get load state
74
+ state = client.get_load_state(collection_name="my_collection")
75
+
76
+ # Get collection statistics
77
+ stats = client.get_collection_stats(collection_name="my_collection")
78
+ ```
79
+
80
+ ## Guidance
81
+
82
+ - Quick create is best for prototyping; use custom schema for production.
83
+ - A collection must be **loaded** before search or query operations.
84
+ - Before dropping a collection, confirm with the user — this deletes all data.
85
+ - Use `enable_dynamic_field=True` to allow inserting fields not defined in the schema.
86
+ - Use `truncate_collection` to clear all data while preserving the collection structure.
@@ -0,0 +1,24 @@
1
+ # Database Management
2
+
3
+ ```python
4
+ # Create a database
5
+ client.create_database(db_name="my_database")
6
+
7
+ # List all databases
8
+ databases = client.list_databases()
9
+ # Returns: ["default", "my_database"]
10
+
11
+ # Switch to a database
12
+ client.using_database(db_name="my_database")
13
+
14
+ # Drop a database (must drop all collections first)
15
+ client.drop_database(db_name="my_database")
16
+
17
+ # Or connect to a specific database at init (use the user's actual URI and credentials)
18
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>", db_name="my_database")
19
+ ```
20
+
21
+ ## Guidance
22
+
23
+ - Every Milvus instance has a `"default"` database.
24
+ - Before dropping a database, all collections in it must be dropped first.
@@ -0,0 +1,69 @@
1
+ # Index Management — Detailed Reference
2
+
3
+ ## Create Index
4
+
5
+ ```python
6
+ index_params = client.prepare_index_params()
7
+
8
+ # Vector index
9
+ index_params.add_index(
10
+ field_name="embedding",
11
+ index_type="HNSW", # See index types table below
12
+ metric_type="COSINE", # "COSINE", "L2", "IP"
13
+ params={"M": 16, "efConstruction": 256}
14
+ )
15
+
16
+ # Optional: scalar index
17
+ index_params.add_index(
18
+ field_name="text",
19
+ index_type="" # Auto-select for scalars
20
+ )
21
+
22
+ client.create_index(
23
+ collection_name="my_collection",
24
+ index_params=index_params
25
+ )
26
+ ```
27
+
28
+ ## Common Index Types
29
+
30
+ | Index Type | For | Key Params | Notes |
31
+ |------------|-----|------------|-------|
32
+ | `AUTOINDEX` | Dense vectors | Auto-tuned | Recommended for most cases |
33
+ | `FLAT` | Dense vectors | None | Brute force, 100% recall |
34
+ | `IVF_FLAT` | Dense vectors | `nlist` | Good balance |
35
+ | `IVF_SQ8` | Dense vectors | `nlist` | Compressed, less memory |
36
+ | `HNSW` | Dense vectors | `M`, `efConstruction` | High recall, more memory |
37
+ | `DISKANN` | Dense vectors | None | Disk-based, large datasets |
38
+ | `SPARSE_INVERTED_INDEX` | Sparse vectors | `drop_ratio_build` | For sparse vectors |
39
+ | `SPARSE_WAND` | Sparse vectors | `drop_ratio_build` | Faster sparse search |
40
+
41
+ ## Metric Types
42
+
43
+ | Metric | Description | Use With |
44
+ |--------|-------------|----------|
45
+ | `"COSINE"` | Cosine similarity (larger = more similar) | Dense vectors |
46
+ | `"L2"` | Euclidean distance (smaller = more similar) | Dense vectors |
47
+ | `"IP"` | Inner product (larger = more similar) | Dense & Sparse vectors |
48
+ | `"BM25"` | BM25 relevance scoring | Full-text search (sparse vectors from built-in tokenizer) |
49
+
50
+ ## Other Index Operations
51
+
52
+ ```python
53
+ # List indexes
54
+ indexes = client.list_indexes(collection_name="my_collection")
55
+
56
+ # Describe an index
57
+ info = client.describe_index(collection_name="my_collection", index_name="my_index")
58
+
59
+ # Drop an index
60
+ client.drop_index(collection_name="my_collection", index_name="my_index")
61
+ ```
62
+
63
+ ## Guidance
64
+
65
+ - `AUTOINDEX` is recommended for most use cases.
66
+ - An index is required before loading a collection.
67
+ - After creating an index, load the collection before searching.
68
+ - Sparse vectors only support `"IP"` metric type.
69
+ - For full-text search, use `"BM25"` metric type with `SPARSE_INVERTED_INDEX` or `SPARSE_WAND`.
@@ -0,0 +1,29 @@
1
+ # Partition Management
2
+
3
+ ```python
4
+ # Create a partition
5
+ client.create_partition(collection_name="my_collection", partition_name="partition_A")
6
+
7
+ # List partitions
8
+ partitions = client.list_partitions(collection_name="my_collection")
9
+ # Returns: ["_default", "partition_A"]
10
+
11
+ # Check if partition exists
12
+ exists = client.has_partition(collection_name="my_collection", partition_name="partition_A")
13
+
14
+ # Load specific partitions
15
+ client.load_partitions(collection_name="my_collection", partition_names=["partition_A"])
16
+
17
+ # Release specific partitions
18
+ client.release_partitions(collection_name="my_collection", partition_names=["partition_A"])
19
+
20
+ # Drop a partition
21
+ client.drop_partition(collection_name="my_collection", partition_name="partition_A")
22
+ ```
23
+
24
+ ## Guidance
25
+
26
+ - Every collection has a `_default` partition.
27
+ - Use `is_partition_key=True` on a field to enable automatic partitioning by field value.
28
+ - A partition must be loaded before search.
29
+ - Before dropping a partition, confirm with the user — all data in it will be deleted.
@@ -0,0 +1,150 @@
1
+ # Common Patterns
2
+
3
+ > **Note:** All patterns below use `<USER_URI>` and `<USER_TOKEN>` as connection placeholders. Always ask the user for their actual connection details before writing code. For local development, use Milvus Lite (`uri="./milvus.db"`) only if the user explicitly requests it.
4
+
5
+ ## RAG Pipeline Pattern
6
+
7
+ ```python
8
+ from pymilvus import MilvusClient, DataType, model
9
+
10
+ # 1. Connect (ask user for URI and credentials)
11
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>")
12
+
13
+ # 2. Set up embedding model
14
+ embedding_fn = model.dense.SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
15
+
16
+ # 3. Create collection (dim must match embedding model output)
17
+ schema = client.create_schema(auto_id=True, enable_dynamic_field=True)
18
+ schema.add_field("id", DataType.INT64, is_primary=True)
19
+ schema.add_field("text", DataType.VARCHAR, max_length=2048)
20
+ schema.add_field("embedding", DataType.FLOAT_VECTOR, dim=384) # all-MiniLM-L6-v2 outputs 384-dim
21
+ schema.add_field("source", DataType.VARCHAR, max_length=256)
22
+
23
+ index_params = client.prepare_index_params()
24
+ index_params.add_index(field_name="embedding", index_type="AUTOINDEX", metric_type="COSINE")
25
+
26
+ client.create_collection(collection_name="knowledge_base", schema=schema, index_params=index_params)
27
+
28
+ # 4. Insert documents — generate real vectors from text chunks
29
+ chunks = ["Milvus is a vector database...", "RAG combines retrieval and generation..."]
30
+ vectors = embedding_fn.encode_documents(chunks)
31
+
32
+ client.insert("knowledge_base", data=[
33
+ {"text": chunk, "embedding": vec, "source": "doc1.pdf"}
34
+ for chunk, vec in zip(chunks, vectors)
35
+ ])
36
+
37
+ # 5. Retrieve relevant context — use the SAME embedding model
38
+ query = "What is a vector database?"
39
+ query_vectors = embedding_fn.encode_queries([query])
40
+
41
+ results = client.search(
42
+ collection_name="knowledge_base",
43
+ data=query_vectors,
44
+ limit=5,
45
+ output_fields=["text", "source"],
46
+ search_params={"metric_type": "COSINE"}
47
+ )
48
+ ```
49
+
50
+ ## Quick Semantic Search Pattern
51
+
52
+ ```python
53
+ from pymilvus import MilvusClient, model
54
+
55
+ # Simplest possible setup (Milvus Lite for local dev)
56
+ client = MilvusClient(uri="./search.db")
57
+ embedding_fn = model.dense.SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
58
+
59
+ # Prepare data — vectors come from embedding model
60
+ texts = ["first document", "second document", "third document"]
61
+ vectors = embedding_fn.encode_documents(texts)
62
+
63
+ client.create_collection(collection_name="docs", dimension=384)
64
+ client.insert("docs", data=[
65
+ {"id": i, "vector": vec, "text": txt}
66
+ for i, (vec, txt) in enumerate(zip(vectors, texts))
67
+ ])
68
+
69
+ # Search — encode query with the same model
70
+ query_vectors = embedding_fn.encode_queries(["search query"])
71
+ results = client.search("docs", data=query_vectors, limit=10, output_fields=["text"])
72
+ ```
73
+
74
+ ## Hybrid Search Pattern (Dense + Sparse)
75
+
76
+ ```python
77
+ from pymilvus import MilvusClient, DataType, AnnSearchRequest, RRFRanker
78
+
79
+ # Ask user for connection details
80
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>")
81
+
82
+ # Schema with both dense and sparse vectors
83
+ schema = client.create_schema(auto_id=True)
84
+ schema.add_field("id", DataType.INT64, is_primary=True)
85
+ schema.add_field("text", DataType.VARCHAR, max_length=2048)
86
+ schema.add_field("dense_embedding", DataType.FLOAT_VECTOR, dim=768)
87
+ schema.add_field("sparse_embedding", DataType.SPARSE_FLOAT_VECTOR)
88
+
89
+ index_params = client.prepare_index_params()
90
+ index_params.add_index(field_name="dense_embedding", index_type="AUTOINDEX", metric_type="COSINE")
91
+ index_params.add_index(field_name="sparse_embedding", index_type="SPARSE_INVERTED_INDEX", metric_type="IP")
92
+
93
+ client.create_collection(collection_name="hybrid_col", schema=schema, index_params=index_params)
94
+
95
+ # Search with both vectors and fuse results
96
+ # dense_query_vector and sparse_query_vector come from your respective embedding models
97
+ req1 = AnnSearchRequest(data=[dense_query_vector], anns_field="dense_embedding",
98
+ param={"metric_type": "COSINE"}, limit=20)
99
+ req2 = AnnSearchRequest(data=[sparse_query_vector], anns_field="sparse_embedding",
100
+ param={"metric_type": "IP"}, limit=20)
101
+
102
+ results = client.hybrid_search(
103
+ collection_name="hybrid_col",
104
+ reqs=[req1, req2],
105
+ ranker=RRFRanker(k=60),
106
+ limit=10,
107
+ output_fields=["text"]
108
+ )
109
+ ```
110
+
111
+ ## Full-Text Search Pattern (BM25)
112
+
113
+ ```python
114
+ from pymilvus import MilvusClient, DataType, Function, FunctionType
115
+
116
+ # Ask user for connection details
117
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>")
118
+
119
+ schema = client.create_schema(auto_id=True)
120
+ schema.add_field("id", DataType.INT64, is_primary=True)
121
+ schema.add_field("title", DataType.VARCHAR, max_length=512)
122
+ schema.add_field("body", DataType.VARCHAR, max_length=4096, enable_analyzer=True)
123
+ schema.add_field("body_sparse", DataType.SPARSE_FLOAT_VECTOR)
124
+
125
+ schema.add_function(Function(
126
+ name="body_bm25",
127
+ input_field_names=["body"],
128
+ output_field_names=["body_sparse"],
129
+ function_type=FunctionType.BM25,
130
+ ))
131
+
132
+ index_params = client.prepare_index_params()
133
+ index_params.add_index(field_name="body_sparse", index_type="AUTOINDEX", metric_type="BM25")
134
+
135
+ client.create_collection(collection_name="articles", schema=schema, index_params=index_params)
136
+
137
+ # Insert — only provide text, sparse vector is auto-generated by BM25 function
138
+ client.insert("articles", data=[
139
+ {"title": "Intro to ML", "body": "Machine learning is a subset of artificial intelligence..."},
140
+ ])
141
+
142
+ # Search with raw text — no embedding model needed, Milvus handles BM25 tokenization
143
+ results = client.search(
144
+ collection_name="articles",
145
+ data=["machine learning fundamentals"],
146
+ anns_field="body_sparse",
147
+ limit=10,
148
+ output_fields=["title", "body"]
149
+ )
150
+ ```
@@ -0,0 +1,90 @@
1
+ # User & Role Management (RBAC)
2
+
3
+ ## User Operations
4
+
5
+ ```python
6
+ # Create a user
7
+ client.create_user(user_name="analyst", password="SecureP@ss123")
8
+
9
+ # List users
10
+ users = client.list_users()
11
+
12
+ # Describe a user (shows assigned roles)
13
+ info = client.describe_user(user_name="analyst")
14
+
15
+ # Update password
16
+ client.update_password(user_name="analyst", old_password="SecureP@ss123", new_password="NewP@ss456")
17
+
18
+ # Grant role to user
19
+ client.grant_role(user_name="analyst", role_name="read_only")
20
+
21
+ # Revoke role from user
22
+ client.revoke_role(user_name="analyst", role_name="read_only")
23
+
24
+ # Drop a user
25
+ client.drop_user(user_name="analyst")
26
+ ```
27
+
28
+ ## Role Operations
29
+
30
+ ```python
31
+ # Create a role
32
+ client.create_role(role_name="read_only")
33
+
34
+ # List roles
35
+ roles = client.list_roles()
36
+
37
+ # Grant privilege (v2 API — recommended)
38
+ client.grant_privilege_v2(
39
+ role_name="read_only",
40
+ privilege="Search", # e.g., "Search", "Insert", "Query", "Delete"
41
+ collection_name="my_collection", # Use "*" for all collections
42
+ db_name="default" # Use "*" for all databases
43
+ )
44
+
45
+ # Built-in privilege groups
46
+ client.grant_privilege_v2(
47
+ role_name="admin_role",
48
+ privilege="ClusterAdmin", # See privilege groups below
49
+ collection_name="*",
50
+ db_name="*"
51
+ )
52
+
53
+ # Revoke privilege
54
+ client.revoke_privilege_v2(
55
+ role_name="read_only",
56
+ privilege="Search",
57
+ collection_name="my_collection",
58
+ db_name="default"
59
+ )
60
+
61
+ # Describe role (see granted privileges)
62
+ info = client.describe_role(role_name="read_only")
63
+
64
+ # Drop a role
65
+ client.drop_role(role_name="read_only")
66
+ ```
67
+
68
+ ## Built-in Privilege Groups
69
+
70
+ | Group | Scope |
71
+ |-------|-------|
72
+ | `ClusterAdmin` | Full cluster access |
73
+ | `ClusterReadOnly` | Read-only cluster access |
74
+ | `ClusterReadWrite` | Read-write cluster access |
75
+ | `DatabaseAdmin` | Full database access |
76
+ | `DatabaseReadOnly` | Read-only database access |
77
+ | `DatabaseReadWrite` | Read-write database access |
78
+ | `CollectionAdmin` | Full collection access |
79
+ | `CollectionReadOnly` | Read-only collection access |
80
+ | `CollectionReadWrite` | Read-write collection access |
81
+
82
+ ## Common Individual Privileges
83
+
84
+ `Search`, `Query`, `Insert`, `Delete`, `Upsert`, `CreateIndex`, `DropIndex`, `CreateCollection`, `DropCollection`, `Load`, `Release`, `CreatePartition`, `DropPartition`
85
+
86
+ ## Guidance
87
+
88
+ - Recommended workflow: create role -> grant privileges -> create user -> assign role.
89
+ - Use `"*"` for collection_name/db_name to grant on all resources.
90
+ - Before dropping a user or role, confirm with the user.
@@ -0,0 +1,247 @@
1
+ # Vector Operations — Detailed Reference
2
+
3
+ Target collection must exist and be loaded.
4
+
5
+ > **Never use fake or placeholder vectors** (e.g., `[0.1, 0.2, ...]`). Always generate vectors from an embedding model. Use `pip install "pymilvus[model]"` for built-in embedding support, or use any external embedding model (OpenAI, Cohere, HuggingFace, etc.).
6
+
7
+ ## Embedding Model Setup
8
+
9
+ ```python
10
+ # Option 1: Built-in pymilvus embedding (pip install "pymilvus[model]")
11
+ from pymilvus import model
12
+ embedding_fn = model.dense.SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
13
+
14
+ # Encode documents for insertion
15
+ doc_vectors = embedding_fn.encode_documents(["AI advances in 2024", "ML basics for beginners"])
16
+ # Encode queries for search (use the SAME model that encoded the stored documents)
17
+ query_vectors = embedding_fn.encode_queries(["What is artificial intelligence?"])
18
+
19
+ # Option 2: OpenAI embeddings (pip install openai)
20
+ from openai import OpenAI
21
+ openai_client = OpenAI()
22
+ response = openai_client.embeddings.create(input=["some text"], model="text-embedding-3-small")
23
+ vectors = [item.embedding for item in response.data]
24
+ ```
25
+
26
+ ## Insert
27
+
28
+ ```python
29
+ docs = ["AI advances in 2024", "ML basics for beginners"]
30
+ vectors = embedding_fn.encode_documents(docs)
31
+
32
+ data = [
33
+ {"id": 1, "text": docs[0], "embedding": vectors[0]},
34
+ {"id": 2, "text": docs[1], "embedding": vectors[1]},
35
+ ]
36
+ res = client.insert(collection_name="my_collection", data=data)
37
+ # Returns: {"insert_count": 2, "ids": [1, 2]}
38
+ ```
39
+
40
+ ## Upsert (insert or update if PK exists)
41
+
42
+ ```python
43
+ res = client.upsert(collection_name="my_collection", data=data)
44
+ # Returns: {"upsert_count": 2}
45
+ ```
46
+
47
+ ## Search (vector similarity)
48
+
49
+ ```python
50
+ query_vectors = embedding_fn.encode_queries(["What is artificial intelligence?"])
51
+
52
+ results = client.search(
53
+ collection_name="my_collection",
54
+ data=query_vectors, # Vectors from embedding model
55
+ anns_field="embedding", # Vector field name
56
+ limit=10, # Top-K
57
+ output_fields=["text", "id"], # Fields to return
58
+ filter='age > 20 and status == "active"', # Optional scalar filter
59
+ search_params={
60
+ "metric_type": "COSINE",
61
+ "params": {"nprobe": 10} # Index-specific params
62
+ }
63
+ )
64
+ # Returns: List[List[dict]]
65
+ # Each hit: {"id": 1, "distance": 0.95, "entity": {"text": "AI advances..."}}
66
+ ```
67
+
68
+ ## Hybrid Search (multi-vector with reranking)
69
+
70
+ ```python
71
+ from pymilvus import AnnSearchRequest, RRFRanker, WeightedRanker
72
+
73
+ # dense_query_vector and sparse_query_vector come from your embedding models
74
+ req1 = AnnSearchRequest(
75
+ data=[dense_query_vector],
76
+ anns_field="dense_embedding",
77
+ param={"metric_type": "COSINE", "params": {"nprobe": 10}},
78
+ limit=10
79
+ )
80
+ req2 = AnnSearchRequest(
81
+ data=[{1: 0.5, 100: 0.3}], # Sparse vector
82
+ anns_field="sparse_embedding",
83
+ param={"metric_type": "IP"},
84
+ limit=10
85
+ )
86
+
87
+ # RRF reranking
88
+ results = client.hybrid_search(
89
+ collection_name="my_collection",
90
+ reqs=[req1, req2],
91
+ ranker=RRFRanker(k=60),
92
+ limit=10,
93
+ output_fields=["text"]
94
+ )
95
+
96
+ # Or weighted reranking
97
+ results = client.hybrid_search(
98
+ collection_name="my_collection",
99
+ reqs=[req1, req2],
100
+ ranker=WeightedRanker(0.7, 0.3),
101
+ limit=10
102
+ )
103
+ ```
104
+
105
+ ## Full-Text Search
106
+
107
+ Full-text search uses Milvus's built-in BM25 tokenizer to convert text into sparse vectors automatically.
108
+
109
+ ### Setup: Collection with Full-Text Search
110
+
111
+ ```python
112
+ from pymilvus import MilvusClient, DataType, Function, FunctionType
113
+
114
+ client = MilvusClient(uri="<USER_URI>", token="<USER_TOKEN>")
115
+
116
+ schema = client.create_schema()
117
+ schema.add_field("id", DataType.INT64, is_primary=True, auto_id=True)
118
+ schema.add_field("text", DataType.VARCHAR, max_length=1000, enable_analyzer=True)
119
+ schema.add_field("sparse", DataType.SPARSE_FLOAT_VECTOR)
120
+
121
+ # Define BM25 function to auto-convert text -> sparse vector
122
+ bm25_function = Function(
123
+ name="text_bm25",
124
+ input_field_names=["text"],
125
+ output_field_names=["sparse"],
126
+ function_type=FunctionType.BM25,
127
+ )
128
+ schema.add_function(bm25_function)
129
+
130
+ index_params = client.prepare_index_params()
131
+ index_params.add_index(field_name="sparse", index_type="AUTOINDEX", metric_type="BM25")
132
+
133
+ client.create_collection(collection_name="full_text_col", schema=schema, index_params=index_params)
134
+ ```
135
+
136
+ ### Search with Text
137
+
138
+ ```python
139
+ results = client.search(
140
+ collection_name="full_text_col",
141
+ data=["machine learning algorithms"], # Raw text query
142
+ anns_field="sparse",
143
+ limit=10,
144
+ output_fields=["text"]
145
+ )
146
+ ```
147
+
148
+ ## Search Iterator (paginated search over large results)
149
+
150
+ ```python
151
+ query_vectors = embedding_fn.encode_queries(["search query text"])
152
+
153
+ iterator = client.search_iterator(
154
+ collection_name="my_collection",
155
+ data=query_vectors,
156
+ anns_field="embedding",
157
+ batch_size=100,
158
+ limit=10000,
159
+ output_fields=["text"],
160
+ search_params={"metric_type": "COSINE", "params": {"nprobe": 10}}
161
+ )
162
+
163
+ results = []
164
+ while True:
165
+ batch = iterator.next()
166
+ if not batch:
167
+ break
168
+ results.extend(batch)
169
+
170
+ iterator.close()
171
+ ```
172
+
173
+ ## Query Iterator (paginated filter-based retrieval)
174
+
175
+ ```python
176
+ iterator = client.query_iterator(
177
+ collection_name="my_collection",
178
+ filter='age > 20',
179
+ output_fields=["text", "age"],
180
+ batch_size=100,
181
+ limit=10000
182
+ )
183
+
184
+ results = []
185
+ while True:
186
+ batch = iterator.next()
187
+ if not batch:
188
+ break
189
+ results.extend(batch)
190
+
191
+ iterator.close()
192
+ ```
193
+
194
+ ## Query (filter-based retrieval)
195
+
196
+ ```python
197
+ results = client.query(
198
+ collection_name="my_collection",
199
+ filter='id in [1, 2, 3]',
200
+ output_fields=["text", "embedding"],
201
+ limit=100
202
+ )
203
+ ```
204
+
205
+ ## Get (by primary key)
206
+
207
+ ```python
208
+ results = client.get(
209
+ collection_name="my_collection",
210
+ ids=[1, 2, 3],
211
+ output_fields=["text"]
212
+ )
213
+ ```
214
+
215
+ ## Delete
216
+
217
+ ```python
218
+ # By primary keys
219
+ client.delete(collection_name="my_collection", ids=[1, 2, 3])
220
+
221
+ # By filter expression
222
+ client.delete(collection_name="my_collection", filter='status == "obsolete"')
223
+ ```
224
+
225
+ ## Filter Expression Syntax
226
+
227
+ | Expression | Example |
228
+ |---|---|
229
+ | Comparison | `age > 20` |
230
+ | Equality | `status == "active"` |
231
+ | IN list | `id in [1, 2, 3]` |
232
+ | AND/OR | `age > 20 and status == "active"` |
233
+ | String match | `text like "hello%"` |
234
+ | Array contains | `ARRAY_CONTAINS(tags, "ml")` |
235
+ | JSON field | `json_field["key"] > 100` |
236
+ | Match all | `id > 0` |
237
+
238
+ ## Guidance
239
+
240
+ - **Never use fake or placeholder vectors.** Always generate vectors from an embedding model.
241
+ - The query embedding model must be the **same model** used to generate the stored vectors.
242
+ - The `data` parameter in search must match the collection's vector dimension exactly.
243
+ - For full-text search, pass raw text strings as `data` — Milvus handles tokenization via BM25.
244
+ - For large inserts, batch data into chunks (e.g., 1000 rows per batch).
245
+ - Always specify `output_fields` to control which fields are returned.
246
+ - For large result sets, use `search_iterator` or `query_iterator` instead of increasing `limit`.
247
+ - Always call `iterator.close()` when done to release server resources.