惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
腾讯CDC
aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
Engineering at Meta
Engineering at Meta
C
Check Point Blog
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
WordPress大学
WordPress大学
博客园 - 司徒正美

LangChain Forum - Topics tagged python-help

Llama-server process has terminated: invalid argument --load-mode with Ollama client 0.32.6 and langchain-ollama 1.1.0 Langchain Certified Agent Engineer Exam - Exam link not received and no response Null-drift: A bare-metal O(1) Memory Store for continuous LangGraph agents Clarification needed: Assistant config vs context and graph initialization Proposal: a small local helper for readable run traces via PR Proxy Authentication Required 407 What is the right way to dynamically create and run a graph? Re-Implement claude code's dynamic workflow using langchian & deepagents How to define a correct state for multi-agent system Response Format Groq Model Pydantic I hope to get some recommendations for practical skills Interrupt does not work correctly in LangGraph The Qwen3.6b model in fireworks through initchatmodel reporting hugely inflated tokens For parallel execution in Node, should i use the functional API? Potential Enhancement: Django-Managed PostgresSaver Pre-interrupt() code re-runs on resume — anti-pattern, or is there a sanctioned way to detect resume? Interrupt parallel branch execution Best practices for self-hosting LangGraph Server OSS without LangGraph keys Dynamically Enabling/Disabling Graphs in a LangGraph Server at Runtime LangGraph thread copy can take 12+ minutes: recommended production pattern? Will DeltaChannel be the default for AgentState.messages, or expected to stay opt-in? Proposal: additional docs for implementing custom DB checkpointers or a guide on generic base checkpointer Prompt_cache_retention: '24h' supported in langchain agents and where to provide it, inside invoke or while creating client? Could RAG pipelines realistically cause deployment timeouts, is Render suitable for first-time RAG deployments? How do I use langchain_postgres' init_vectorstore_table correctly? Proposal: Graph-wide default error handler for StateGraph (fallback for nodes without error_handler) Support timedelta for CachePolicy.ttl, consistent with TimeoutPolicy Anyone confirms this issue that deepagent ui streaming is disturb by update in deepagent or bug issue Best Stack for Building AI Applications Seeking help regarding the connection between Websocket and tool calls
Structured data fields (1000+): Dedicated LLM channel vs ...
2026-03-24 · via LangChain Forum - Topics tagged python-help

Your instinct is correct; structured data should not use vector retrieval for field selection. Vector embeddings are designed for semantic similarity in unstructured text, not for precise field mapping in structured schemas. For your 255-field KYC API scenario, I have another recommendation which is two-stage hierarchical LLM pipeline.


Why not vector retrieval for fields?

  • Vector similarity is approximate — you need exact field selection

  • Embeddings don’t understand field semantics (e.g., registered_capital vs paid_in_capital might embed similarly but mean different things)

  • You lose the ability to apply business logic (e.g., “always include operating_status when querying legal fields”)


The two-stage LLM approach

Stage 1: Category selection

The first LLM call identifies which high-level categories are relevant to the user’s query (Again I am just making up an example for better clarity).

CATEGORY_SCHEMA = """
registration: Company name, incorporation date, registered address, business scope
financials: Capital, revenue, credit rating, tax information
legal: Licenses, litigation, penalties, compliance status
personnel: Legal representative, shareholders, beneficial owners, board members
operations: Business activities, branches, subsidiaries, partnerships
"""

async def select_categories(query: str) -> list[str]:
    """LLM selects relevant categories from user query."""
    prompt = f"""Given this query: "{query}"
    
    Return relevant categories from: {CATEGORY_SCHEMA}
    
    Output only a JSON array of category names, e.g. ["legal", "personnel"]
    """
    response = await llm.ainvoke(prompt)
    return parse_json(response)  # ["legal", "personnel"]


Stage 2: Field selection within categories

The second LLM call operates only on the fields within the selected categories.

FIELD_DEFINITIONS = {
    "legal": {
        "licenses": "Business licenses and permits held by the company",
        "litigation_records": "Ongoing or historical lawsuits",
        "administrative_penalties": "Fines or sanctions from regulators",
        "bankruptcy_status": "Bankruptcy filings or insolvency proceedings"
    },
    "personnel": {
        "legal_representative": "Primary legal representative of the company",
        "shareholders": "List of shareholders and ownership percentages",
        "beneficial_owners": "Ultimate beneficial owners (UBO)",
        "board_members": "Members of the board of directors"
    }
    # ... other categories
}

async def select_fields(query: str, categories: list[str]) -> list[str]:
    """LLM selects specific fields within the chosen categories."""
    # Build schema only for selected categories
    relevant_schema = {}
    for cat in categories:
        relevant_schema.update(FIELD_DEFINITIONS[cat])
    
    prompt = f"""Given this query: "{query}"
    
    Select relevant fields from:
    {format_schema(relevant_schema)}
    
    Output only a JSON array of field names.
    """
    response = await llm.ainvoke(prompt)
    return parse_json(response)  # ["litigation_records", "administrative_penalties", "beneficial_owners"]


Combined pipeline

async def query_field(company_name: str, query: str) -> str:
    # Stage 1: Select categories
    categories = await select_categories(query)
    
    # Stage 2: Select fields within categories
    fields = await select_fields(query, categories)
    
    if not fields:
        return f"No relevant fields found for: '{query}'"
    
    # Fetch and format data
    result = await api.kyc(company_name)
    data = result["result"]["Data"]
    
    lines = []
    for field in fields:
        value = deep_get(data, field)
        if value == "unknown":
            lines.append(f"【{field}】No data available")
        else:
            lines.append(f"【{field}】")
            lines.append(format_value(value))
    
    return "\n".join(lines)


Wrapping as an agent tool

The agent sees a clean, intent-focused interface:

from langchain_core.tools import tool

@tool
async def query_company_fields(company_name: str, query: str) -> str:
    """Query specific information from a company's KYC profile.

    This tool searches across company registration, financial, legal, personnel,
    and operational data. It automatically identifies relevant fields based on
    your natural language query.

    Example queries:
      - "What is the registered address and incorporation date?"
      - "Who are the beneficial owners and their nationalities?"
      - "Is the company currently active? Any legal issues?"
      - "What licenses does the company hold?"
      - "Show me the company's capital structure and credit rating"

    Args:
        company_name: The company to look up.
        query: Natural language description of the information needed.

    Returns:
        Formatted field values from the company's KYC record.
    """
    return await query_field(company_name, query)

“Multiple identical categories from different providers”

If you’re aggregating fields from multiple APIs (e.g., Provider1’s company_info, Provider2’s company_info), namespace them in your schema:

FIELD_DEFINITIONS = {
    "registration_provider1": {
        "provider1_registered_name": "...",
        "provider1_incorporation_date": "..."
    },
    "registration_provider2": {
        "provider2_registered_name": "...",
        "provider2_incorporation_date": "..."
    }
}

The LLM can reason about which provider is relevant based on the query context or you can merge them into canonical fields if they’re semantically identical.


“Can LLM handle 10,000 fields?”

With two-stage selection: yes. Stage 1 reduces 10,000 fields to ~100–200 based on category. Stage 2 operates on that subset. Modern LLMs (GPT-4, Claude 3.5) can easily handle schemas of this size, especially with structured output modes (JSON schema constraints).


“Should I use vector retrieval for field names?”

Only if you’ve exhausted hierarchical LLM selection and are still hitting context limits (unlikely below 50,000 fields). Vector retrieval introduces approximation error that’s unnecessary when you have clean structured metadata. Reserve it for unstructured content (documents, images, Q&A pairs) where semantic similarity is the goal.