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

# Triplet Embeddings

> Index graph triplets as embeddings to enable TRIPLET_COMPLETION search

## When to use this

You need `SearchType.TRIPLET_COMPLETION` to return results. This search type matches queries against text representations of graph triplets (source → relationship → target). The `create_triplet_embeddings` pipeline creates these embeddings.

**Before you start:**

* Complete [Quickstart](/getting-started/quickstart) to understand basic operations
* Ensure you have [LLM Providers](/setup-configuration/llm-providers) configured
* Have an existing knowledge graph (add → cognify completed)

## Code in Action

```python theme={null}
import asyncio
import cognee
from cognee import SearchType
from cognee.memify_pipelines.create_triplet_embeddings import create_triplet_embeddings
from cognee.modules.users.methods import get_default_user

async def main():
    await cognee.add(
        ["GraphRAG combines vector search with graph traversal for better context."],
        dataset_name="triplet_demo",
    )
    await cognee.cognify(datasets=["triplet_demo"])

    user = await get_default_user()
    await create_triplet_embeddings(user=user, dataset="triplet_demo")

    results = await cognee.search(
        query_type=SearchType.TRIPLET_COMPLETION,
        query_text="How does GraphRAG work?",
    )
    for result in results:
        print(result)

asyncio.run(main())
```

## What Just Happened

1. **Add + Cognify** — builds a knowledge graph with entities and relationships from your text.
2. **`get_default_user()`** — retrieves the authenticated user. This pipeline requires a `User` object with write access to the dataset.
3. **`create_triplet_embeddings(user, dataset)`** — iterates over all graph triplets, converts each to a text representation, and indexes them in the vector DB.
4. **Search with `TRIPLET_COMPLETION`** — queries the new `Triplet_text` collection by semantic similarity.

## What Changed in Your Graph

* The `Triplet_text` collection is populated in the vector DB. Each entry is a text representation of a graph triplet (source → relationship → target).
* `SearchType.TRIPLET_COMPLETION` queries now return results by matching your query against these triplet embeddings.

<Accordion title="Parameters">
  - **`user`** (`User`, required) — authenticated user with write access. Obtain via `await get_default_user()`.
  - **`dataset`** (`str`, default: `"main_dataset"`) — the dataset whose graph triplets to index.
  - **`run_in_background`** (`bool`, default: `False`) — run asynchronously and return immediately.
  - **`triplets_batch_size`** (`int`, default: `100`) — how many triplets to index per batch. Lower values use less memory; higher values are faster.
</Accordion>

<Accordion title="Under the hood">
  Two tasks run in sequence:

  1. **`get_triplet_datapoints`** — iterates over graph triplets and yields `Triplet` objects with embeddable text.
  2. **`index_data_points`** — indexes each triplet in the vector DB under the `Triplet_text` collection.
</Accordion>

<Accordion title="Troubleshooting">
  * **Empty results from `TRIPLET_COMPLETION`** — ensure the graph has been built (cognify completed) and that `create_triplet_embeddings` finished without errors.
  * **Error: no graph data found** — run `cognee.add()` and `cognee.cognify()` before calling this pipeline.
  * **LLM errors** — verify that your LLM provider is configured. See [LLM Providers](/setup-configuration/llm-providers).
  * **Permission errors** — the user must have write access to the target dataset. See [Permissions](/core-concepts/multi-user-mode/permissions-system/datasets).
</Accordion>

<Columns cols={3}>
  <Card title="Memify Concept" icon="sparkles" href="/core-concepts/main-operations/legacy-operations/memify">
    Understand how memify pipelines work
  </Card>

  <Card title="Memify Quickstart" icon="brain" href="/guides/memify-quickstart">
    Run the default coding-rules pipeline
  </Card>

  <Card title="Search" icon="search" href="/core-concepts/main-operations/legacy-operations/search">
    Query the enriched graph with specialized search types
  </Card>
</Columns>
