SearchIndex

org.llm4s.rag.permissions.SearchIndex
See theSearchIndex companion object
trait SearchIndex

Top-level search index with permission-based filtering.

SearchIndex is the main entry point for permission-aware RAG operations. It combines:

  • Collection hierarchy management
  • User/group principal mapping
  • Permission-filtered vector search
  • Document ingestion with access control

Query flow:

  1. Resolve accessible collection IDs based on pattern + user authorization
  2. Perform vector search within those collections
  3. Apply document-level permission filtering (readable_by)
  4. Return permission-filtered results

Attributes

Companion
object
Source
SearchIndex.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def clearCollection(collectionPath: CollectionPath): Result[Long]

Delete all documents in a collection.

Delete all documents in a collection.

Does not delete the collection itself.

Value parameters

collectionPath

The collection to clear

Attributes

Returns

Number of chunks deleted

Source
SearchIndex.scala
def close(): Unit

Close the search index and release resources.

Close the search index and release resources.

Attributes

Source
SearchIndex.scala

Access to collection management

Access to collection management

Attributes

Source
SearchIndex.scala
def deleteDocument(collectionPath: CollectionPath, documentId: String): Result[Long]

Delete a document from a collection.

Delete a document from a collection.

Removes all chunks associated with the document.

Value parameters

collectionPath

The collection containing the document

documentId

The document identifier

Attributes

Returns

Number of chunks deleted

Source
SearchIndex.scala

Drop the permission schema.

Drop the permission schema.

WARNING: This is destructive and will delete all permission data. Only use for testing or complete reset.

Attributes

Returns

Success or error

Source
SearchIndex.scala
def ingest(collectionPath: CollectionPath, documentId: String, chunks: Seq[ChunkWithEmbedding], metadata: Map[String, String], readableBy: Set[PrincipalId]): Result[Seq[String]]

Ingest a document into a specific collection.

Ingest a document into a specific collection.

The collection must:

  • Exist (call ensureExists first if needed)
  • Be a leaf collection (can contain documents)

Value parameters

chunks

Pre-chunked content with embeddings

collectionPath

Target collection path

documentId

Unique document identifier

metadata

Document metadata

readableBy

Document-level permission override (empty = inherit from collection)

Attributes

Returns

the ids the chunks are stored under, one per chunk in the order given: the id a search result for each carries

Source
SearchIndex.scala

Initialize the permission schema.

Initialize the permission schema.

Creates necessary tables and indexes if they don't exist. Safe to call multiple times (idempotent).

Attributes

Returns

Success or error

Source
SearchIndex.scala

Access to principal (user/group) management

Access to principal (user/group) management

Attributes

Source
SearchIndex.scala
def query(auth: UserAuthorization, collectionPattern: CollectionPattern, queryVector: Array[Float], topK: Int, additionalFilter: Option[MetadataFilter]): Result[Seq[ScoredRecord]]

Main query method with permission filtering.

Main query method with permission filtering.

Performs a two-stage permission filter:

  1. Collection-level: Only search collections the user can access
  2. Document-level: Only return documents the user can read

Value parameters

additionalFilter

Optional additional metadata filter

auth

User authorization context

collectionPattern

Pattern to filter collections (e.g., confluence/STAR)

queryVector

Embedding vector for semantic search

topK

Maximum number of results to return

Attributes

Returns

Permission-filtered search results

Source
SearchIndex.scala

Concrete methods

Delete a document from every collection that holds it.

Delete a document from every collection that holds it.

RAG.deleteDocument calls it, so that deleting a document by id removes what ingest wrote for it in any collection, not only what the plain ingest API wrote. The default deletes it from each leaf collection in turn and stops at the first failure; an index that can do it in one statement should override it.

Value parameters

documentId

The document identifier

Attributes

Returns

Number of chunks deleted

Source
SearchIndex.scala
def keywordQuery(auth: UserAuthorization, collectionPattern: CollectionPattern, queryText: String, topK: Int, additionalFilter: Option[MetadataFilter]): Result[Seq[KeywordSearchResult]]

Keyword (full-text) search with the same two-stage permission filter as query.

Keyword (full-text) search with the same two-stage permission filter as query.

RAG.queryWithPermissions calls it for every fusion strategy except FusionStrategy.VectorOnly, and fuses its results with query's as RAG.query does. An index without keyword search keeps this default, which fails rather than return vector-only results: configure the pipeline with .vectorOnly to query such an index.

Value parameters

additionalFilter

Optional additional metadata filter

auth

User authorization context

collectionPattern

Pattern to filter collections

queryText

Text for keyword search

topK

Maximum number of results

Attributes

Returns

Permission-filtered keyword results, best first

Source
SearchIndex.scala

Get the PostgreSQL configuration if this is a PostgreSQL-backed index.

Get the PostgreSQL configuration if this is a PostgreSQL-backed index.

This is used by RAGConfig to automatically configure the underlying vector store when a SearchIndex is provided.

Attributes

Returns

Some(config) if PostgreSQL-backed, None otherwise

Source
SearchIndex.scala
def stats(collectionPath: CollectionPath): Result[CollectionStats]

Get statistics for a collection.

Get statistics for a collection.

Value parameters

collectionPath

The collection path

Attributes

Returns

Collection statistics

Source
SearchIndex.scala