> For the complete documentation index, see [llms.txt](https://docs.graphlit.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.graphlit.dev/api-guides/use-cases/conversations/rag-with-entity-filtering.md).

# 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

***
