> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vectoraidb.actian.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure HNSW parameters

> Set HNSW parameters when creating a collection to control the tradeoff between search speed, recall accuracy, and memory usage in VectorAI DB.

Configure HNSW parameters when creating a collection to balance search speed, accuracy, and memory usage. Custom parameters are useful when default settings do not meet your recall or latency requirements.

## Create a collection with custom parameters

The following example creates a collection with custom `m` and `ef_construct` values inside `HnswConfigDiff`.

<CodeGroup>
  ```python Python theme={null}
  from actian_vectorai import VectorAIClient, VectorParams, Distance, HnswConfigDiff

  # Connect to VectorAI DB server (use context manager to ensure proper connection)
  with VectorAIClient("localhost:6574") as client:
      # Create collection with custom HNSW parameters
      client.collections.create(
          "my_collection",  # Collection name
          vectors_config=VectorParams(size=384, distance=Distance.Cosine),  # Vector configuration
          hnsw_config=HnswConfigDiff(
              m=32,              # More connections for better recall
              ef_construct=200   # Higher quality index
          )
      )
      print("✓ Collection 'my_collection' created successfully")
  ```

  ```javascript JavaScript theme={null}
  import { VectorAIClient } from '@actian/vectorai-client';

  async function main() {
      // Connect to VectorAI DB server
      const client = new VectorAIClient('localhost:6574');

      // Create collection with custom HNSW parameters
      await client.collections.create('my_collection', {
          dimension: 384,
          distanceMetric: 'COSINE',
          hnswConfig: {
              m: 32,              // More connections for better recall
              efConstruct: 200    // Higher quality index
          }
      });

      console.log("Collection 'my_collection' created successfully");
  }

  main().catch(console.error);
  ```
</CodeGroup>

<Note>
  Higher parameter values improve accuracy at the cost of increased memory usage, slower index construction, and longer search times. Lower values prioritize speed and memory efficiency but can reduce recall.
</Note>

## Create a collection with default settings

When you omit `hnsw_config`, VectorAI DB applies balanced default settings that work well for general-purpose vector search. Test with your data to determine if custom parameters provide improvements.

<CodeGroup>
  ```python Python theme={null}
  from actian_vectorai import VectorAIClient, VectorParams, Distance

  # Connect to VectorAI DB server
  with VectorAIClient("localhost:6574") as client:
      # Collection with default index settings
      client.collections.create(
          "my_collection",  # Collection name
          vectors_config=VectorParams(size=384, distance=Distance.Cosine)  # Vector configuration
          # hnsw_m=16 (default)
          # hnsw_ef_construct=200 (default)
          # hnsw_ef_search=50 (default)
      )
      print("✓ Collection created successfully")
  ```

  ```javascript JavaScript theme={null}
  import { VectorAIClient } from '@actian/vectorai-client';

  async function main() {
      // Connect to VectorAI DB server
      const client = new VectorAIClient('localhost:6574');

      // Collection with default index settings
      await client.collections.create('my_collection', {
          dimension: 384,
          distanceMetric: 'COSINE'
          // hnswConfig uses defaults:
          // m: 16
          // efConstruct: 200
      });

      console.log("Collection created successfully");
  }

  main().catch(console.error);
  ```
</CodeGroup>
