Skip to main content

LangChain tool for semantic search over Federal Acquisition Regulations (FAR)

Project description

FAR Search Tool for LangChain

A LangChain tool for semantic search over Federal Acquisition Regulations (FAR).

Enable your AI agents to search and understand U.S. government contracting regulations, procurement rules, and compliance requirements.

Installation

pip install far-search-tool

Quick Start

Basic Usage (Free Tier)

from far_search import FARSearchTool

# Initialize the tool
tool = FARSearchTool()

# Search FAR regulations
result = tool.invoke({
    "query": "small business set aside requirements",
    "top_k": 5
})

print(result)

With RapidAPI Key (Higher Limits)

For production use with higher rate limits, get an API key from RapidAPI.

from far_search import FARSearchTool

tool = FARSearchTool(rapidapi_key="your-rapidapi-key")

result = tool.invoke({
    "query": "cybersecurity requirements for contractors"
})

Use with LangChain Agents

from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from far_search import FARSearchTool

# Initialize LLM and tool
llm = ChatOpenAI(model="gpt-4")
tools = [FARSearchTool()]

# Create agent
agent = initialize_agent(
    tools=tools,
    llm=llm,
    agent=AgentType.OPENAI_FUNCTIONS,
    verbose=True
)

# Ask about regulations
response = agent.run(
    "What are the FAR requirements for small business subcontracting plans?"
)
print(response)

Use with LangGraph

from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from far_search import FARSearchTool

# Create agent with FAR search capability
agent = create_react_agent(
    ChatOpenAI(model="gpt-4"),
    tools=[FARSearchTool()]
)

# Query the agent
result = agent.invoke({
    "messages": [("user", "What cybersecurity clauses should I include in a DoD contract?")]
})

Features

  • Semantic Search: Find relevant regulations using natural language queries
  • Pre-vectorized Data: 617 FAR clauses with pre-computed embeddings for fast search
  • LLM-Optimized Output: Results formatted for easy consumption by language models
  • Retry Logic: Built-in handling for transient failures
  • Dual API Support: Free tier or RapidAPI for production use

API Reference

FARSearchTool

FARSearchTool(
    rapidapi_key: str = None,      # Optional RapidAPI key for paid tier
    base_url: str = None,          # Override API URL (for self-hosted)
    timeout: int = 30,             # Request timeout in seconds
    max_retries: int = 2           # Retry attempts on failure
)

Input Schema

Parameter Type Default Description
query str required Natural language search query
top_k int 5 Number of results (1-20)

Output

Returns a formatted string containing matching FAR clauses with:

  • Clause ID and title
  • Relevance score
  • Source reference
  • URL to official documentation
  • Clause text (truncated if long)

Example Queries

  • "Small business set aside requirements"
  • "Cybersecurity contract clauses"
  • "Payment terms for government contracts"
  • "Contractor ethics and conduct rules"
  • "Cost accounting standards"
  • "Intellectual property rights in contracts"
  • "Subcontracting plan requirements"
  • "Contract termination procedures"

Pricing

Tier Rate Limit Price
Free 100 requests/day $0
Pro 5,000 requests/month $29/month
Ultra 150,000 requests/month $199/month

Get your API key at RapidAPI.

Error Handling

from far_search import FARSearchTool, FARAPIError, FARRateLimitError

tool = FARSearchTool()

try:
    result = tool.invoke({"query": "my query"})
except FARRateLimitError:
    print("Rate limit exceeded. Upgrade your plan or wait.")
except FARAPIError as e:
    print(f"API error: {e}")

Requirements

  • Python 3.9+
  • langchain >= 0.1.0
  • requests >= 2.28.0
  • pydantic >= 2.0.0

License

MIT License - see LICENSE for details.

Links

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

far_search_tool-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

far_search_tool-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file far_search_tool-0.1.1.tar.gz.

File metadata

  • Download URL: far_search_tool-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for far_search_tool-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dc10fd3237a4033958065e8120a365b20e55aa4bf39b538d05c5a7cab3c500df
MD5 5ffa039bb54b1f5322934d64e1596b0f
BLAKE2b-256 2e90a21b4c91d26aee717dc18dbe009d1e4ec1de6a94239e0ab1adc491ec3e4b

See more details on using hashes here.

File details

Details for the file far_search_tool-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for far_search_tool-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33b8f6dc61ea5059f416b47c1e0b07a7139b51addde2735d5d33ee4ca934f42a
MD5 cee7d913133eae0c540a5059720c2e0e
BLAKE2b-256 f5111ae37af4a980d87f3908c769f88fb4a1f8fc110b2c2d5daa89cef23d149f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page