self-querying-retriever
БесплатноБез исполняемых скриптовНе проверенLangChain SelfQueryRetriever pattern. LLM infers structured metadata filters from natural language ("books by Asimov after 2000" -> filter author=Asimov AND…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Self-Querying Retriever
The Pattern
User types natural language. The LLM produces a structured (search_string, filter) tuple that the retriever executes against a vector store with metadata filtering.
"books by Asimov after 2000"
|
v
{ query: "books", filter: AND(eq(author, "Asimov"), gt(year, 2000)) }
Separating semantic query from symbolic filter is the key. Semantic similarity cannot express year > 2000; metadata filters cannot express "books about first contact". Together they work.
Core Flow
[NL query] -> [Structured query LLM] -> {query, filter} -> [vector store + metadata filter] -> docs
^
|
metadata schema description
LangChain 0.3+ SelfQueryRetriever
from langchain.chains.query_constructor.schema import AttributeInfo
from langchain.retrievers.self_query.base import SelfQueryRetriever
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings
from langchain_anthropic import ChatAnthropic
from langchain_core.documents import Document
docs = [
Document(page_content="Foundation is a 1951 novel about...",
metadata={"title": "Foundation", "author": "Isaac Asimov",
"year": 1951, "genre": "science fiction", "rating": 4.4}),
Document(page_content="The Gods Themselves explores...",
metadata={"title": "The Gods Themselves", "author": "Isaac Asimov",
"year": 1972, "genre": "science fiction", "rating": 4.1}),
Document(page_content="Prelude to Foundation is set before...",
metadata={"title": "Prelude to Foundation", "author": "Isaac Asimov",
"year": 1988, "genre": "science fiction", "rating": 4.0}),
Document(page_content="Forward the Foundation...",
metadata={"title": "Forward the Foundation", "author": "Isaac Asimov",
"year": 1993, "genre": "science fiction", "rating": 4.2}),
]
vstore = Chroma.from_documents(docs, OpenAIEmbeddings(model="text-embedding-3-small"))
metadata_field_info = [
AttributeInfo(name="title", description="Book title", type="string"),
AttributeInfo(name="author", description="Author full name", type="string"),
AttributeInfo(name="year", description="Publication year", type="integer"),
AttributeInfo(name="genre",
description="Genre: 'science fiction', 'fantasy', 'mystery', 'non-fiction'",
type="string"),
AttributeInfo(name="rating",
description="Average reader rating 1.0-5.0", type="float"),
]
document_content_description = "Summary of a novel"
llm = ChatAnthropic(model="claude-sonnet-4-5-20250929", temperature=0)
retriever = SelfQueryRetriever.from_llm(
llm=llm,
vectorstore=vstore,
document_contents=document_content_description,
metadata_field_info=metadata_field_info,
enable_limit=True, # "top 3 books..." populates `k`
use_original_query=False, # pass the rewritten semantic query
verbose=True,
)
docs = retriever.invoke("Asimov novels after 1970 rated above 4")
The LLM emits a structured query that the translator converts to Chroma's filter syntax:
{
"query": "novels",
"filter": {
"$and": [
{"author": {"$eq": "Isaac Asimov"}},
{"year": {"$gt": 1970}},
{"rating": {"$gt": 4}},
]
},
"limit": 4
}
Supported Comparators and Operators
Built-in (availability varies per backend):
| Comparator | Semantics | Ex |
|---|---|---|
eq |
equal | author == "Asimov" |
ne |
not equal | genre != "fantasy" |
gt gte |
greater than (or equal) | year > 2000 |
lt lte |
less than (or equal) | rating <= 3 |
contain |
substring match | title contains "Foundation" |
in nin |
(not) in set | genre in ["sci-fi","fantasy"] |
like |
regex/wildcard (backend) | title like "Forward*" |
Operators: and, or, not.
Pinecone, Weaviate, Qdrant, pgvector, Elasticsearch, Milvus, Chroma, and MongoDB each have a translator class in langchain.retrievers.self_query.*.
Qdrant Example (production vector DB)
from langchain_qdrant import QdrantVectorStore
vstore = QdrantVectorStore.from_documents(
docs, OpenAIEmbeddings(), url="http://localhost:6333", collection_name="books"
)
retriever = SelfQueryRetriever.from_llm(
llm=llm,
vectorstore=vstore,
document_contents=document_content_description,
metadata_field_info=metadata_field_info,
)
The Qdrant translator maps to native must/should/must_not clauses with range, match, match_any.
Custom Prompt for Better Filter Inference
The default prompt is good but domain-specific hints pay off on narrow schemas.
from langchain.chains.query_constructor.base import (
StructuredQueryOutputParser, get_query_constructor_prompt,
)
from langchain.retrievers.self_query.chroma import Ch
Установить self-querying-retriever в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditFAQ
Что делает скилл self-querying-retriever?
LangChain SelfQueryRetriever pattern. LLM infers structured metadata filters from natural language ("books by Asimov after 2000" -> filter author=Asimov AND year>2000). Metadata schema declaration, comparators and operators, LlamaIndex AutoRetriever equivalent, combining with hybrid search, evaluation of filter correctness. USE WHEN: user mentions "self-querying retriever", "SelfQueryRetriever", "auto retriever", "metadata filter from query", "NL to filter", "AutoRetriever" DO NOT USE FOR: text-to-SQL on tables - use `tabular-rag`; plain query rewriting - use `query-transformations`; hybrid search - use `hybrid-search`
Как установить скилл self-querying-retriever?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл self-querying-retriever запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
agent-skill-stack
Find, evaluate, and assemble the smallest compatible set of AI Agent Skills for an end-to-end natural-language goal. Use when a user wants Skills for a…
от GitHubbuild-evidence-map
Build an auditable evidence map for a contested technical choice, research synthesis, proposal review, or consequential decision. Use when Copilot must…
от GitHubpinecone-rag
Build production RAG pipelines and persistent agent memory using Pinecone as the vector database backend. ALWAYS USE THIS SKILL when the user mentions…
от GitHubqdrant-monitoring-debugging
Diagnoses Qdrant production issues using metrics and observability tools. Use when someone reports 'optimizer stuck', 'indexing too slow', 'memory too high'…
от GitHub