# HNSWLib Self Query Retriever

This example shows how to use a self query retriever with an HNSWLib vector store.

## Usage

import CodeBlock from "@theme/CodeBlock";
import Example from "@examples/retrievers/hnswlib_self_query.ts";

<CodeBlock language="typescript">{Example}</CodeBlock>

You can also initialize the retriever with default search parameters that apply in
addition to the generated query:

```typescript
const selfQueryRetriever = await SelfQueryRetriever.fromLLM({
  llm,
  vectorStore,
  documentContents,
  attributeInfo,
  /**
   * We need to use a translator that translates the queries into a
   * filter format that the vector store can understand. We provide a basic translator
   * translator here, but you can create your own translator by extending BaseTranslator
   * abstract class. Note that the vector store needs to support filtering on the metadata
   * attributes you want to query on.
   */
  structuredQueryTranslator: new FunctionalTranslator(),
  searchParams: {
    filter: (doc: Document) => doc.metadata && doc.metadata.rating > 8.5,
    mergeFiltersOperator: "and",
  },
});
```