Querying Golden's Knowledge Graph with LangChain's GoldenQueryAPIWrapper
Posted: Nov 22, 2024.
Golden provides a powerful knowledge graph that can be queried using natural language. In this guide, we'll explore how to use LangChain's GoldenQueryAPIWrapper to programmatically access Golden's Query API and retrieve structured data.
What is GoldenQueryAPIWrapper?
GoldenQueryAPIWrapper is a LangChain utility class that provides a simple interface to Golden's Query API. It allows you to make natural language queries to Golden's knowledge graph and retrieve structured information about various entities like companies, products, people, and more.
This wrapper is particularly useful when you need to:
- Get information about companies in specific industries
- Find products from particular companies
- Research funding information about startups
- Discover relationships between different entities
Reference
Method | Description |
---|---|
__init__(golden_api_key: str = None) | Initialize the wrapper with your Golden API key. If not provided, it will look for the GOLDEN_API_KEY environment variable |
run(query: str) -> str | Execute a natural language query and return the results as a JSON string |
How to Use GoldenQueryAPIWrapper
Setup and Installation
Before using the wrapper, you'll need to:
- Sign up for a Golden account at golden.com
- Get your API key from Golden API Settings
- Set up your environment:
Basic Usage
Here's how to make simple queries using the wrapper:
This will return a list of companies in the nanotech industry, with their basic information.
Advanced Queries
The wrapper supports various types of natural language queries. Here are some examples:
Working with Results
The API returns structured data that includes various properties about the entities. Here's how to process more complex results:
Error Handling
Since the API requires authentication and may have rate limits, it's good practice to add error handling:
The GoldenQueryAPIWrapper provides a powerful way to access structured data from Golden's knowledge graph. By combining it with proper error handling and result processing, you can build robust applications that leverage this vast knowledge base.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.
LangChain DocsJoin 10,000+ subscribers
Every 2 weeks, latest model releases and industry news.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.