> ## 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.

# Quickstart

> Create a collection, insert vectors, and run your first similarity search.

Before starting, make sure VectorAI DB is running and your SDK is installed. See the [Docker setup guide](/home/installation/instructions) if you haven't done that yet.

<Tabs>
  <Tab title="Python">
    ## Prerequisites

    To use the Python SDK, make sure you have:

    * Python 3.10 or later
    * numpy 1.26 or later
    * grpcio 1.80 or later
    * pydantic 2.10 or later

    ## Step 1: Create a collection

    Connect to VectorAI DB and create a collection named `products` with dimension 128 and cosine distance metric.

    <Tabs>
      <Tab title="Synchronous">
        ```python theme={null}
        from actian_vectorai import VectorAIClient, VectorParams, Distance

        with VectorAIClient("localhost:6574") as client:
            info = client.health_check()
            print(f"Connected to {info['title']} v{info['version']}")

            client.collections.create(
                "products",
                vectors_config=VectorParams(size=128, distance=Distance.Cosine)
            )
            print("Collection 'products' created successfully")
        ```
      </Tab>

      <Tab title="Asynchronous">
        ```python theme={null}
        import asyncio
        from actian_vectorai import AsyncVectorAIClient, VectorParams, Distance

        async def main():
            async with AsyncVectorAIClient("localhost:6574") as client:
                info = await client.health_check()
                print(f"Connected to {info['title']} v{info['version']}")

                await client.collections.create(
                    "products",
                    vectors_config=VectorParams(size=128, distance=Distance.Cosine)
                )
                print("Collection 'products' created successfully")

        asyncio.run(main())
        ```
      </Tab>
    </Tabs>

    ## Step 2: Insert vectors

    ```python theme={null}
    import random
    from typing import List
    from actian_vectorai import VectorAIClient, PointStruct

    NUM_VECTORS = 100
    DIMENSION = 128

    def generate_sample_products(
        num_products: int = 100,
        dimension: int = 128,
        base_price: float = 10.0,
        price_variance: float = 100.0,
        seed: int = None
    ) -> List[PointStruct]:
        if seed is not None:
            random.seed(seed)

        categories = ["electronics", "clothing", "food"]
        points = []

        for i in range(num_products):
            category = categories[i % 3]
            price = float(i * base_price + random.random() * price_variance)
            in_stock = (i % 2 == 0)

            points.append(
                PointStruct(
                    id=i,
                    vector=[random.gauss(0, 1) for _ in range(dimension)],
                    payload={
                        "id": i,
                        "category": category,
                        "price": round(price, 2),
                        "in_stock": in_stock,
                    }
                )
            )

        return points

    with VectorAIClient("localhost:6574") as client:
        print(f"Inserting {NUM_VECTORS} vectors...")

        points = generate_sample_products(NUM_VECTORS, DIMENSION, seed=42)

        client.points.upsert("products", points)
        print(f"Inserted {NUM_VECTORS} vectors")

        count = client.points.count("products")
        print(f"Vector count: {count}")
    ```

    ## Step 3: Search for similar vectors

    ```python theme={null}
    from actian_vectorai import VectorAIClient
    import random

    DIMENSION = 128
    COLLECTION = "products"

    with VectorAIClient("localhost:6574") as client:
        print("Searching for similar vectors...")
        query = [random.gauss(0, 1) for _ in range(DIMENSION)]
        results = client.points.search(COLLECTION, vector=query, limit=5)

        print(f"Found {len(results)} results:")
        for i, result in enumerate(results):
            print(f"[{i+1}] ID: {result.id}, Score: {result.score:.4f}")

        print("\nRetrieving vector details...")
        retrieved = client.points.get(COLLECTION, ids=[results[0].id])
        print(f"Top result payload: {retrieved[0].payload}")
    ```

    The following output is an example. Your scores will vary.

    ```
    Searching for similar vectors...
    Found 5 results:
    [1] ID: 39, Score: 29.2119
    [2] ID: 54, Score: 27.3639
    [3] ID: 76, Score: 23.6023
    [4] ID: 31, Score: 21.2087
    [5] ID: 22, Score: 17.9858

    Retrieving vector details...
    Top result payload: {'price': 451.6, 'id': 39, 'in_stock': False, 'category': 'electronics'}
    ```

    ## Step 4: Delete collection

    ```python theme={null}
    from actian_vectorai import VectorAIClient

    with VectorAIClient("localhost:6574") as client:
        client.collections.delete("products")
        print("Collection 'products' deleted successfully")
    ```
  </Tab>

  <Tab title="JavaScript">
    ## Prerequisites

    To use the JavaScript SDK, make sure you have:

    * Node.js 18 or later
    * npm 9 or later

    ## Step 1: Create a collection

    Connect to VectorAI DB and create a collection named `products` with dimension 128 and cosine distance metric. Save each step below to a single file called `quickstart.ts` and run it with `npx tsx quickstart.ts`.

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

    const DIMENSION = 128;
    const COLLECTION = 'products';

    const client = new VectorAIClient('localhost:6574');

    const info = await client.healthCheck();
    console.log(`Connected to ${info.title} v${info.version}`);

    await client.collections.create(COLLECTION, {
        dimension: DIMENSION,
        distanceMetric: 'COSINE',
    });
    console.log(`Collection '${COLLECTION}' created successfully`);
    ```

    ## Step 2: Generate sample data

    Create a helper function to generate sample product vectors with metadata.

    ```typescript theme={null}
    function generateSampleProducts(numProducts: number, dimension: number) {
        const categories = ['electronics', 'clothing', 'food'];
        return Array.from({ length: numProducts }, (_, i) => ({
            id: i,
            vector: Array.from({ length: dimension }, () => Math.random() * 2 - 1),
            payload: {
                id: i,
                category: categories[i % 3],
                price: parseFloat((i * 10 + Math.random() * 100).toFixed(2)),
                in_stock: i % 2 === 0,
            },
        }));
    }
    ```

    ## Step 3: Insert vectors

    ```typescript theme={null}
    const NUM_VECTORS = 100;

    console.log(`Inserting ${NUM_VECTORS} vectors...`);
    const points = generateSampleProducts(NUM_VECTORS, DIMENSION);

    await client.points.upsert(COLLECTION, points, { wait: true });
    console.log(`Inserted ${NUM_VECTORS} vectors`);

    const count = await client.points.count(COLLECTION);
    console.log(`Vector count: ${count}`);
    ```

    ## Step 4: Search for similar vectors

    ```typescript theme={null}
    console.log('\nSearching for similar vectors...');
    const query = Array.from({ length: DIMENSION }, () => Math.random() * 2 - 1);
    const results = await client.points.search(COLLECTION, query, { limit: 5 });

    console.log(`Found ${results.length} results:`);
    for (const [i, result] of results.entries()) {
        console.log(`[${i + 1}] ID: ${result.id}, Score: ${result.score.toFixed(4)}`);
    }

    console.log('\nRetrieving vector details...');
    const retrieved = await client.points.get(COLLECTION, [results[0].id]);
    console.log(`Top result payload: ${JSON.stringify(retrieved[0].payload)}`);
    ```

    The following output is an example. Your scores will vary.

    ```
    Searching for similar vectors...
    Found 5 results:
    [1] ID: 39, Score: 29.2119
    [2] ID: 54, Score: 27.3639
    [3] ID: 76, Score: 23.6023
    [4] ID: 31, Score: 21.2087
    [5] ID: 22, Score: 17.9858

    Retrieving vector details...
    Top result payload: {"price":451.6,"id":39,"in_stock":false,"category":"electronics"}
    ```

    ## Step 5: Delete collection

    ```typescript theme={null}
    await client.collections.delete(COLLECTION);
    console.log(`Collection '${COLLECTION}' deleted successfully`);

    client.close();
    ```
  </Tab>
</Tabs>

## Next steps

<CardGroup cols={2}>
  <Card title="Core concepts" icon="book-open" href="/home/getting-started/overview">
    Understand the data model, architecture, and how search works.
  </Card>

  <Card title="Python SDK reference" icon="code" href="/sdks/python/reference">
    Namespaces, configuration, filters, and error handling.
  </Card>

  <Card title="JavaScript SDK reference" icon="code" href="/sdks/javascript/reference">
    Client setup, namespaces, and TypeScript types.
  </Card>

  <Card title="Integrations" icon="plug" href="/docs/integrations/index">
    Connect VectorAI DB to LangChain and LlamaIndex.
  </Card>

  <Card title="Academy" icon="graduation-cap" href="/academy/tutorials">
    Tutorials for semantic search, hybrid search, RAG, and more.
  </Card>
</CardGroup>
