# RAG with Entity Filtering

## User Intent

"How do I ask questions filtered by specific entities? Show me entity-aware RAG queries."

## Operation

**SDK Method**: `promptConversation()` with entity-filtered content\
**GraphQL**: RAG with entity observations filter\
**Use Case**: Entity-scoped question answering

## Prerequisites

* Conversation created
* Content with extracted entities
* Understanding of entity filtering

***

## Complete Code Example (TypeScript)

```typescript
import { Graphlit } from 'graphlit-client';
import { ObservableTypes } from 'graphlit-client/dist/generated/graphql-types';

const graphlit = new Graphlit();

// Create conversation
const conversation = await graphlit.createConversation({
  name: "Entity-Filtered Q&A"
});

// Find entity
const person = await graphlit.queryObservables({
  search: "Kirk Marple",
  filter: { types: [ObservableTypes.Person] }
});

const personId = person.observables.results[0]?.observable.id;

// Ask question filtered by entity
const response = await graphlit.promptConversation({
  prompt: "What projects has Kirk worked on?",
  id: conversation.createConversation.id,
  filter: {
    observations: [{
      type: ObservableTypes.Person,
      observable: { id: personId }
    }]
  }
});

console.log(response.message.message);
```

***

## Key Patterns

### 1. Single Entity Scope

Scope RAG to one entity:

```typescript
filter: {
  observations: [{
    type: ObservableTypes.Person,
    observable: { id: personId }
  }]
}
```

### 2. Multi-Entity Context

Content mentioning multiple entities:

```typescript
filter: {
  observations: [
    { observable: { id: personId } },
    { observable: { id: orgId } }
  ]
}
```

### 3. Entity Type Filtering

Any entity of type:

```typescript
filter: {
  observations: [{
    type: ObservableTypes.Organization
  }]
}
```

***

## Use Cases

**"What did Person X say about Product Y?"**\
\&#xNAN;**"Show me all discussions about Organization Z"**\
\&#xNAN;**"Summarize mentions of Event W"**\
\&#xNAN;**"Compare Person A and Person B's views"**

***

## Developer Hints

* Entity filters reduce RAG search space
* More precise answers
* Combine with semantic search
* Citations include entity context
* Great for scoped Q\&A

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.graphlit.dev/api-guides/use-cases/conversations/rag-with-entity-filtering.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
