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)

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:

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

2. Multi-Entity Context

Content mentioning multiple entities:

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

3. Entity Type Filtering

Any entity of type:

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

Use Cases

"What did Person X say about Product Y?" "Show me all discussions about Organization Z" "Summarize mentions of Event W" "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


Last updated

Was this helpful?