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

# Debugging

> Verify synonym index usage and inspect expansions

## Which Index a Query Uses

Run `EXPLAIN` to verify that the query uses the correct synonym index. Look for `Synonyms: <index>` in the output.

```sql SQL theme={null}
EXPLAIN (COSTS OFF)
SELECT id FROM mock_items
WHERE description ||| (SELECT pdb.expand('couch', rule) FROM shop_synonyms);
```

```ts Drizzle theme={null}
import { sql } from "drizzle-orm";

await db.execute(sql`
  EXPLAIN (COSTS OFF)
  SELECT id FROM mock_items
  WHERE description ||| (SELECT pdb.expand('couch', rule) FROM shop_synonyms);
`);
```

```python Django theme={null}
from django.db import connection

with connection.cursor() as cursor:
    cursor.execute("""
        EXPLAIN (COSTS OFF)
        SELECT id FROM mock_items
        WHERE description ||| (SELECT pdb.expand('couch', rule) FROM shop_synonyms);
    """)
    results = cursor.fetchall()
```

```python SQLAlchemy theme={null}
from sqlalchemy import text

with engine.connect() as conn:
    results = conn.execute(text("""
        EXPLAIN (COSTS OFF)
        SELECT id FROM mock_items
        WHERE description ||| (SELECT pdb.expand('couch', rule) FROM shop_synonyms);
    """)).all()
```

```ruby Rails theme={null}
ActiveRecord::Base.connection.exec_query <<~SQL
  EXPLAIN (COSTS OFF)
  SELECT id FROM mock_items
  WHERE description ||| (SELECT pdb.expand('couch', rule) FROM shop_synonyms);
SQL
```

```cs EF Core theme={null}
using Microsoft.EntityFrameworkCore;

var plan = await dbContext.Database
    .SqlQueryRaw<string>("""
        EXPLAIN (COSTS OFF)
        SELECT id FROM mock_items
        WHERE description ||| (SELECT pdb.expand('couch', rule) FROM shop_synonyms);
        """)
    .ToListAsync();
```

```csv Expected Response theme={null}
                                                                                            QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Custom Scan (ParadeDB Base Scan) on mock_items
   Table: mock_items
   Index: search_idx
   Exec Method: ColumnarExecState
   Columnar: id
   Scores: false
   Tantivy Query: {"with_index":{"query":{"match":{"field":"description","value":"couch","tokenizer":null,"distance":null,"transposition_cost_one":null,"prefix":null,"conjunction_mode":false}}}}
   Synonyms: shop_synonyms_idx
(8 rows)
```

## Checking an Expansion

To see what a synonym index turns a text into, call `pdb.synonym_expansion`:

```sql SQL theme={null}
SELECT * FROM pdb.synonym_expansion('shop_synonyms_idx', 'red sofa');
```

```ts Drizzle theme={null}
import { sql } from "drizzle-orm";

await db.execute(sql`
  SELECT * FROM pdb.synonym_expansion('shop_synonyms_idx', 'red sofa');
`);
```

```python Django theme={null}
from django.db import connection

with connection.cursor() as cursor:
    cursor.execute("""
        SELECT * FROM pdb.synonym_expansion('shop_synonyms_idx', 'red sofa');
    """)
    results = cursor.fetchall()
```

```python SQLAlchemy theme={null}
from sqlalchemy import text

with engine.connect() as conn:
    results = conn.execute(text("""
        SELECT * FROM pdb.synonym_expansion('shop_synonyms_idx', 'red sofa');
    """)).all()
```

```ruby Rails theme={null}
ActiveRecord::Base.connection.exec_query <<~SQL
  SELECT * FROM pdb.synonym_expansion('shop_synonyms_idx', 'red sofa');
SQL
```

```cs EF Core theme={null}
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

var expansions = await dbContext.Database
    .SqlQueryRaw<SynonymExpansion>("""
        SELECT * FROM pdb.synonym_expansion('shop_synonyms_idx', 'red sofa');
        """)
    .ToListAsync();

public class SynonymExpansion
{
    [Column("position")]
    public int Position { get; set; }

    [Column("token")]
    public string Token { get; set; } = "";

    [Column("alternatives")]
    public string[] Alternatives { get; set; } = [];
}
```

```csv Expected Response theme={null}
 position | token |    alternatives
----------+-------+--------------------
        0 | red   | {red}
        1 | sofa  | {couch,divan,sofa}
(2 rows)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.