### Local Server Setup: PostgreSQL and Qdrant Source: https://context7.com/sciphi-ai/agent-search/llms.txt Steps to set up a local Agent Search engine. This involves starting PostgreSQL, populating it from a dataset, starting Qdrant via Docker, and indexing data into Qdrant. ```bash # 1. Start PostgreSQL sudo service postgresql start # 2. Populate PostgreSQL from the HuggingFace AgentSearch-V1 dataset python -m agent_search.scripts.populate_postgres_from_hf run # 3. Start Qdrant vector store via Docker docker run -p 6333:6333 -p 6334:6334 \ -v $(pwd)/qdrant_storage:/qdrant/storage:z \ qdrant/qdrant # 4. Index documents into Qdrant from PostgreSQL python -m agent_search.scripts.populate_qdrant_from_postgres run --delete_existing=True ``` -------------------------------- ### Install Dependencies and Build Docs Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/README.md Installs necessary dependencies for documentation and then builds the HTML documentation. ```bash pip install -r requirements-docs.txt make clean make html ``` -------------------------------- ### Run the Server Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/quick_start.md Start the AgentSearch application server. ```shell python -m agent_search.app.server ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/README.md Starts a local HTTP server to view the built documentation in a browser. Access it at localhost:8000. ```bash python -m http.server -d build/html/ ``` -------------------------------- ### Launch Postgres Database Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/quick_start.md Start the PostgreSQL service. ```shell sudo service postgresql start ``` -------------------------------- ### Install AgentSearch Source: https://context7.com/sciphi-ai/agent-search/llms.txt Install the agent-search package from PyPI. For development, clone the repository and install in editable mode. Remember to set your SCIPHI_API_KEY environment variable. ```bash # Install from PyPI (Python >=3.9, <3.12) pip install agent-search # For development git clone https://github.com/SciPhi-AI/agent-search.git cd agent-search pip3 install -e . # Set your API key export SCIPHI_API_KEY=your_key_here ``` -------------------------------- ### Install AgentSearch with pip Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/installation.md Use this command for a quick installation of AgentSearch. Ensure you have Python 3.9 or higher installed. ```bash pip install agent-search ``` -------------------------------- ### Start Qdrant Service with Docker Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/quick_start.md Run the Qdrant vector database service using Docker, mounting a local volume for storage. ```shell docker run -p 6333:6333 -p 6334:6334 -v $(pwd)/qdrant_storage:/qdrant/storage:z qdrant/qdrant ``` -------------------------------- ### Set up AgentSearch for Development Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/installation.md Clone the repository and install AgentSearch in editable mode for development. This allows you to make changes to the source code and have them reflected immediately. ```bash git clone https://github.com/SciPhi-AI/agent-search.git cd agent-search pip3 install -e . ``` -------------------------------- ### Custom Search Agent Workflow with AgentSearch Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/index.md Build a custom search agent workflow by defining instructions, performing a search, constructing search context, and generating a completion using the client. This example demonstrates RAG over search results and enforcing a JSON response format. ```python from agent_search import SciPhi import json client = SciPhi() # Specify instructions for the task instruction = "Your task is to perform retrieval augmented generation (RAG) over the given query and search results. Return your answer in a json format that includes a summary of the search results and a list of related queries." query = "What is Fermat's Last Theorem?" # construct search context search_response = client.search(query=query, search_provider='agent-search') search_context = "\n\n".join( f"{idx + 1}. Title: {item['title']}\nURL: {item['url']}\nText: {item['text']}" for idx, item in enumerate(search_response) ).encode('utf-8') # Prefix to enforce a JSON response json_response_prefix = '{"summary":' # Prepare a prompt formatted_prompt = f"### Instruction:{instruction}\n\nQuery:\n{query}\n\nSearch Results:\n${search_context}\n\nQuery:\n{query}\n### Response:\n{json_response_prefix}", # Generate a raw string completion with Sensei-7B-V1 completion = json_response_prefix + client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") print(json.loads(completion)) # { # "summary": "\nFermat's Last Theorem is a mathematical proposition first prop ... ", # "other_queries": ["The role of elliptic curves in the proof of Fermat's Last Theorem", ...] # } ``` -------------------------------- ### LLM Completions Endpoint Response Example Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/api/main.md This is a sample JSON response from the LLM Completions Endpoint, illustrating the structure of a text completion. ```json { "id":"cmpl-f03f53c15a174ffe89bdfc83507de7a9", "object":"text_completion", "created":389200, "model":"SciPhi/Sensei-7B-V1", "choices":[ { "index":0, "text":"The quest for the meaning of life is a profound and multifaceted in", "logprobs":null, "finish_reason":"length" } ], "usage": { "prompt_tokens":49, "total_tokens":65, "completion_tokens":16 } } ``` -------------------------------- ### Recursive Search Agent with Python SDK Source: https://context7.com/sciphi-ai/agent-search/llms.txt Implement a depth-first recursive search using the SciPhi SDK. This example follows related queries to a specified depth and breadth. Ensure SCIPHI_API_KEY is set in the environment. ```python import os from agent_search import SciPhi client = SciPhi(api_key=os.environ.get("SCIPHI_API_KEY")) def generate_answer(query: str) -> dict: return client.get_search_rag_response( query=query, search_provider="agent-search", ) def recursive_search(query: str, depth: int = 3, breadth: int = 1): """ Recursively searches related queries to a given depth. breadth: number of related queries to follow at each level """ initial = generate_answer(query) responses = [(initial["response"], initial["related_queries"][:breadth])] for _ in range(depth - 1): new_related = [] for related_query in responses[-1][1]: result = generate_answer(related_query) if isinstance(result, dict) and "response" in result: new_related.extend(result["related_queries"][:breadth]) responses.append((result["response"], result["related_queries"][:breadth])) responses[-1] = (responses[-1][0], new_related) for response, related in responses: print(response) print("*" * 10) print("Related queries:", related) print("*" * 10) # Run 3 levels deep, following 1 related query per level recursive_search(query="Conservatism", depth=3, breadth=1) ``` -------------------------------- ### Custom Search Agent Workflow with RAG and Completion Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/python_client/main.md Code a custom search agent workflow by specifying instructions for retrieval augmented generation (RAG) and then generating a completion. This example constructs search context from results and prefixes the prompt to enforce JSON output. ```python from agent_search import SciPhi import json client = SciPhi() # Specify instructions for the task instruction = "Your task is to perform retrieval augmented generation (RAG) over the given query and search results. Return your answer in a json format that includes a summary of the search results and a list of related queries." query = "What is Fermat's Last Theorem?" # construct search context search_response = client.search(query=query, search_provider='agent-search') search_context = "\n\n".join( f"{idx + 1}. Title: {item['title']}\nURL: {item['url']}\nText: {item['text']}" for idx, item in enumerate(search_response) ).encode('utf-8') # Prefix to enforce a JSON response json_response_prefix = '{"summary":' # Prepare a prompt formatted_prompt = f"### Instruction:{instruction}\n\nQuery:\n{query}\n\nSearch Results:\n${search_context}\n\nQuery:\n{query}\n### Response:\n{json_response_prefix}", # Generate a raw string completion with Sensei-7B-V1 completion = json_response_prefix + client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") print(json.loads(completion)) # { # "summary": "\nFermat's Last Theorem is a mathematical proposition first prop ... ", # "other_queries": ["The role of elliptic curves in the proof of Fermat's Last Theorem", ...] # } ``` -------------------------------- ### Get Search RAG Response Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/python_client/main.md Retrieves a retrieval-augmented generation (RAG) response by performing a search and then processing the results with a language model. ```APIDOC ## Get Search RAG Response ### Description Retrieves a search RAG (Retrieval-Augmented Generation) response by performing a search and then using a specified language model to generate a summary and related queries. ### Method ```python agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') ``` ### Parameters #### get_search_rag_response - **query** (str) - Required - The search query string. - **search_provider** (str) - Required - The search provider to use. - **llm_model** (str) - Optional - The language model to use for generation (defaults to 'SciPhi/Sensei-7B-V1'). - **temperature** (int) - Optional - The temperature setting for the query (defaults to 0.2). - **top_p** (int) - Optional - The top-p setting for the query (defaults to 0.95). ### Returns - str: A string containing the completed text, typically a summary and related queries. ``` -------------------------------- ### Get Search RAG Response Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/python_client/main.md Call a pre-configured search agent endpoint to perform a search, summarize the result, and generate related queries. Requires SCIPHI_API_KEY in the environment. ```python # Requires SCIPHI_API_KEY in the environment from agent_search import SciPhi client = SciPhi() # Search, then summarize result and generate related queries agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') print(agent_summary) # {'response': "The latest news encompasses ... and its consequences [2].", 'related_queries': ['Details on the...', ...], 'search_results' : [...]} ``` -------------------------------- ### Get Search RAG Response Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/index.md Performs a search, then summarizes the result and generates related queries using a specified LLM and search provider. ```APIDOC ## get_search_rag_response ### Description Performs a search using the specified query and search provider, then summarizes the search results and generates related queries using the specified LLM model. ### Method client.get_search_rag_response ### Parameters - **query** (string) - Required - The search query. - **search_provider** (string) - Required - The search engine to use (e.g., 'bing', 'agent-search'). - **llm_model** (string) - Required - The LLM model to use for summarization and query generation (e.g., 'SciPhi/Sensei-7B-V1'). ### Response Example ```json { "response": "The latest news encompasses ... and its consequences [2].", "related_queries": ["Details on the...", ...], "search_results": [...] } ``` ``` -------------------------------- ### SciPhi Client Initialization and Search Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/python_client/main.md Demonstrates how to initialize the SciPhi client and perform a basic search using a specified provider. ```APIDOC ## SciPhi Client Initialization and Search ### Description Initializes the SciPhi client and performs a search query using a specified search provider. ### Method ```python client = SciPhi() search_response = client.search(query='Quantum Field Theory', search_provider='agent-search') ``` ### Parameters #### search - **query** (str) - Required - The search query string. - **search_provider** (str) - Required - The search provider to use (e.g., 'bing', 'agent-search'). ### Returns - List[Dict]: A list of search results. ``` -------------------------------- ### Launch Local Agent Search Server and Test Source: https://context7.com/sciphi-ai/agent-search/llms.txt Launch the FastAPI search server and test its /search endpoint using curl. Replace with the actual port the server is running on. ```bash # 5. Launch the FastAPI search server python -m agent_search.app.server # The server exposes: # POST /search — local vector + PageRank search # GET /health — health check # Test it: curl -X POST http://localhost:/search \ -H "Content-Type: application/json" \ -d '{ "query": "What is a Lagrangian?", "limit_broad_results": 1000, "limit_deduped_url_results": 100, "limit_hierarchical_url_results": 25, "limit_final_pagerank_results": 10 }' ``` -------------------------------- ### Build Search Context Manually with SciPhi Client Source: https://context7.com/sciphi-ai/agent-search/llms.txt Demonstrates how to perform a search using the SciPhi client, format the results into a search context string, and then use this context with the completion endpoint. Ensure the client is initialized before use. ```python search_results = client.search(query=query, search_provider="agent-search") search_context = "\n\n".join( f"{i+1}. Title: {r['title']}\nURL: {r['url']}\nText: {r['text']}" for i, r in enumerate(search_results) ).encode("utf-8") json_prefix = '{"summary":' prompt = ( f"### Instruction:{instruction}\n\n" f"Query:\n{query}\n\n" f"Search Results:\n{search_context}\n\n" f"Query:\n{query}\n" f"### Response:\n{json_prefix}" ) raw = client.completion( prompt=prompt, llm_model_name="SciPhi/Sensei-7B-V1", llm_max_tokens_to_sample=1024, llm_temperature=0.2, llm_top_p=0.90, ) parsed = json.loads(json_prefix + raw) print(parsed["summary"]) # "Fermat's Last Theorem states that no three positive integers a, b, c satisfy..." print(parsed["other_queries"]) # ["The role of elliptic curves in proving Fermat's Last Theorem", ...] ``` -------------------------------- ### Initialize SciPhi Client Source: https://context7.com/sciphi-ai/agent-search/llms.txt Initialize the SciPhi client for the hosted API. An API key is required, which can be provided directly or via the SCIPHI_API_KEY environment variable. Custom base URLs and timeouts can also be configured. ```python import os from agent_search import SciPhi # Initialize using environment variable client = SciPhi() # Or pass key and custom base URL explicitly client = SciPhi( api_key=os.environ["SCIPHI_API_KEY"], api_base="https://api.sciphi.ai", # default timeout=30, # seconds ) ``` -------------------------------- ### Use OpenAI-Compatible Completions Endpoint Source: https://context7.com/sciphi-ai/agent-search/llms.txt Demonstrates how to access the Sensei-7B model via an OpenAI-compatible completions endpoint. This allows direct LLM interaction with a custom search context and is compatible with any OpenAI API client library. Ensure SCIPHI_API_KEY and SEARCH_CONTEXT environment variables are set. ```bash export SCIPHI_API_KEY=your_key_here export SEARCH_CONTEXT="Fermat's Last Theorem states that no three positive integers..." curl https://api.sciphi.ai/v1/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -d '{ "model": "SciPhi/Sensei-7B-V1", "prompt": "### Instruction:\n\nQuery:\nExplain Fermat'\''s Last Theorem\n\nSearch Results:\n'"$SEARCH_CONTEXT"'\n\nQuery:\nExplain Fermat'\''s Last Theorem\n### Response:\n{\"response":", "temperature": 0.0 }' # Response: # { ``` -------------------------------- ### SciPhi Client Initialization Source: https://context7.com/sciphi-ai/agent-search/llms.txt Initialize the SciPhi client for interacting with the hosted SciPhi API. An API key is required, which can be provided directly or via the SCIPHI_API_API_KEY environment variable. ```APIDOC ## SciPhi Client Initialization The `SciPhi` class is the primary Python client for the hosted SciPhi API. It wraps all HTTP communication, handles authentication, and provides retry/backoff logic. An API key must be provided either directly or via the `SCIPHI_API_KEY` environment variable. ```python import os from agent_search import SciPhi # Initialize using environment variable client = SciPhi() # Or pass key and custom base URL explicitly client = SciPhi( api_key=os.environ["SCIPHI_API_KEY"], api_base="https://api.sciphi.ai", # default timeout=30, # seconds ) ``` ``` -------------------------------- ### Raw LLM Completion with SciPhi.completion() Source: https://context7.com/sciphi-ai/agent-search/llms.txt Generate a raw text completion for a prompt using the SciPhi LLM endpoint. This method offers precise control over prompt formatting and context injection. Requires the `sciphi-synthesizer` package. ```python import json from agent_search import SciPhi client = SciPhi() query = "What is Fermat's Last Theorem?" instruction = ( "Perform RAG over the given query and search results. " "Return JSON with a 'summary' and a list of 'other_queries'." ) ``` -------------------------------- ### Run Basic Search via CLI Source: https://context7.com/sciphi-ai/agent-search/llms.txt Execute a basic search query using the agent_search CLI. Ensure your SCIPHI_API_KEY is exported. ```bash export SCIPHI_API_KEY=your_key_here # Basic search python -m agent_search.scripts.run_search run --query="What is a Lagrangian?" ``` -------------------------------- ### Populate Vector Database (Qdrant) Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/quick_start.md Populate the Qdrant vector database from PostgreSQL, with an option to delete existing data. ```shell python -m agent_search.scripts.populate_qdrant_from_postgres run --delete_existing=True ``` -------------------------------- ### Populate Postgres Database Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/quick_start.md Populate the PostgreSQL database from Hugging Face datasets. ```shell python -m agent_search.scripts.populate_postgres_from_hf run ``` -------------------------------- ### Instantiate and Use SearchResult Source: https://context7.com/sciphi-ai/agent-search/llms.txt Demonstrates how to create a SearchResult object and access its attributes. Used to represent a single document from a search. ```python from agent_search.providers.sciphi import SearchResult result = SearchResult( score=0.9219, url="https://en.wikipedia.org/wiki/Quantum_field_theory", title="Quantum field theory", text="Quantum field theory (QFT) is a theoretical framework...", dataset="wikipedia", metadata={"timestamp": "2023-01-01"}, ) print(result.score) # 0.9219 print(result.title) # "Quantum field theory" print(result.dataset) # "wikipedia" d = result.dict() # serialize to plain dict ``` -------------------------------- ### SciPhi.completion() Source: https://context7.com/sciphi-ai/agent-search/llms.txt Generate a raw text completion for a given prompt using the SciPhi LLM endpoint. This method is useful for precise control over prompt formatting and search context injection, requiring the `sciphi-synthesizer` package. ```APIDOC ## `SciPhi.completion()` — Raw LLM Completion Generates a raw text completion for a fully constructed prompt using the SciPhi LLM endpoint. Useful when you want precise control over prompt formatting and search context injection. Requires the `sciphi-synthesizer` package. ```python import json from agent_search import SciPhi client = SciPhi() query = "What is Fermat's Last Theorem?" instruction = ( "Perform RAG over the given query and search results. " "Return JSON with a 'summary' and a list of 'other_queries'." ) ``` -------------------------------- ### REST API - /v1/completions Source: https://context7.com/sciphi-ai/agent-search/llms.txt OpenAI-compatible completions endpoint for direct access to the Sensei-7B model with a custom search context. Compatible with any OpenAI API client library. ```APIDOC ## REST API — `/v1/completions` Endpoint OpenAI-compatible completions endpoint for direct access to the Sensei-7B model with a custom search context. Compatible with any OpenAI API client library. ```bash export SCIPHI_API_KEY=your_key_here export SEARCH_CONTEXT="Fermat's Last Theorem states that no three positive integers..." curl https://api.sciphi.ai/v1/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -d '{ "model": "SciPhi/Sensei-7B-V1", "prompt": "### Instruction:\n\nQuery:\nExplain Fermat'\''s Last Theorem\n\nSearch Results:\n'"$SEARCH_CONTEXT"'\n\nQuery:\nExplain Fermat'\''s Last Theorem\n### Response:\n{\"response\":", "temperature": 0.0 }' # Response: # { ``` -------------------------------- ### Perform a Search Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/quick_start.md Set your API key and run a search query using the AgentSearch command-line interface. ```shell export SCIPHI_API_KEY=MY_SCIPHI_API_KEY python -m agent_search.scripts.run_search run --query="Your Search Query" ``` -------------------------------- ### Perform RAG Search and Summarization with AgentSearch Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/index.md Use the SciPhi client to perform a search, then summarize the results and generate related queries. Requires SCIPHI_API_KEY to be set in the environment. ```python # Requires SCIPHI_API_KEY in the environment from agent_search import SciPhi client = SciPhi() # Search, then summarize result and generate related queries agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') print(agent_summary) # {'response': "The latest news encompasses ... and its consequences [2].", 'related_queries': ['Details on the...', ...], 'search_results' : [...]} ``` -------------------------------- ### Run RAG Pipeline with Default LLM via CLI Source: https://context7.com/sciphi-ai/agent-search/llms.txt Execute a full Retrieval-Augmented Generation (RAG) pipeline using the default SciPhi Sensei-7B LLM. The SCIPHI_API_KEY must be exported. ```bash export SCIPHI_API_KEY=your_key_here # Using SciPhi Sensei-7B (default) python -m agent_search.scripts.run_rag run \ --query="What is Fermat's last theorem?" ``` -------------------------------- ### Call LLM Completions Endpoint with Curl Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/api/main.md Use this curl command to send a prompt to the SciPhi Sensei model. Ensure your SCIPHI_API_KEY is set and configure SEARCH_CONTEXT and RESPONSE_PREFIX as needed for your integration. ```bash export SEARCH_CONTEXT="N/A" export RESPONSE_PREFIX='{"response":' curl https://api.sciphi.ai/v1/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -d '{ "model": "SciPhi/Sensei-7B-V1", "prompt": "### Instruction:\n\nQuery:\nWhat is the meaning of life?\n\nSearch Results:\n${SEARCH_CONTEXT}\n\nQuery:\nWhat is the meaning of life?\n### Response:\n${RESPONSE_PREFIX}", "temperature": 0.0 }' ``` -------------------------------- ### Run Search Against Custom API Base via CLI Source: https://context7.com/sciphi-ai/agent-search/llms.txt Perform a search query targeting a custom API base URL. Requires the SCIPHI_API_KEY to be set. ```bash export SCIPHI_API_KEY=your_key_here # Against a custom API base python -m agent_search.scripts.run_search run \ --query="What is a Lagrangian?" \ --api_base="https://api.sciphi.ai" ``` -------------------------------- ### Build Custom Search Agent Workflow with RAG Source: https://github.com/sciphi-ai/agent-search/blob/main/README.md Construct a custom search agent workflow by defining instructions, performing a search, preparing the search context, and generating a completion using an LLM. Enforces a JSON response format. ```python # Requires SCIPHI_API_KEY in the environment from agent_search import SciPhi client = SciPhi() # Specify instructions for the task instruction = "Your task is to perform retrieval augmented generation (RAG) over the given query and search results. Return your answer in a json format that includes a summary of the search results and a list of related queries." query = "What is Fermat's Last Theorem?" # construct search context search_response = client.search(query=query, search_provider='agent-search') search_context = "\n\n".join( f"{idx + 1}. Title: {item['title']}\nURL: {item['url']}\nText: {item['text']}" for idx, item in enumerate(search_response) ).encode('utf-8') # Prefix to enforce a JSON response json_response_prefix = '{"summary":' # Prepare a prompt formatted_prompt = f"### Instruction:{instruction}\n\nQuery:\n{query}\n\nSearch Results:\n${search_context}\n\nQuery:\n{query}\n### Response:\n{json_response_prefix}", # Generate a completion with Sensei-7B-V1 completion = json_response_prefix + client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") print(completion) # { # "summary": "\nFermat's Last Theorem is a mathematical proposition first prop ... ", # "other_queries": ["The role of elliptic curves in the proof of Fermat's Last Theorem", ...] # } ``` -------------------------------- ### Perform RAG Search and Summarize Results Source: https://github.com/sciphi-ai/agent-search/blob/main/README.md Use the SciPhi client to perform a search, then summarize the results and generate related queries using a specified LLM and search provider. ```python # Requires SCIPHI_API_KEY in the environment from agent_search import SciPhi client = SciPhi() # Search, then summarize result and generate related queries agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') print(agent_summary) # { 'response': '...', 'other_queries': '...', 'search_results': '...' } ``` -------------------------------- ### Run RAG Pipeline with OpenAI LLM via CLI Source: https://context7.com/sciphi-ai/agent-search/llms.txt Execute a RAG pipeline specifying OpenAI's GPT-3.5-turbo as the LLM. Requires both SCIPHI_API_KEY and OPENAI_API_KEY to be exported. ```bash export SCIPHI_API_KEY=your_key_here export OPENAI_API_KEY=your_openai_key python -m agent_search.scripts.run_rag run \ --query="What is Fermat's last theorem?" \ --llm_provider_name=openai \ --llm_model_name=gpt-3.5-turbo ``` -------------------------------- ### Perform a Search Query Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/api/main.md Use this endpoint to fetch related search results for a given query. Ensure your API key is set in the SCIPHI_API_KEY environment variable and included in the Authorization header. ```bash export SCIPHI_API_KEY=${MY_API_KEY} curl -X POST https://api.sciphi.ai/search \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "What is quantum field theory in curved spacetime?"}' ``` -------------------------------- ### Query AgentSearch REST API /search Endpoint Source: https://context7.com/sciphi-ai/agent-search/llms.txt Demonstrates how to query the hosted REST API's /search endpoint using a cURL command. This is suitable for integrating from non-Python environments or building microservices. Ensure the SCIPHI_API_KEY environment variable is set. ```bash export SCIPHI_API_KEY=your_key_here curl -X POST https://api.sciphi.ai/search \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "What is quantum field theory in curved spacetime?"}' # Response: # [ # { # "score": 0.9219, # "url": "https://en.wikipedia.org/wiki/Quantum%20field%20theory%20in%20curved%20spacetime", # "title": "Quantum field theory in curved spacetime", # "dataset": "wikipedia", # "text": "These theories rely on general relativity to describe a curved background spacetimeவைக்...", # "metadata": {} # }, # ... # ] ``` -------------------------------- ### Instantiate and Use SearchRAGResponse Source: https://context7.com/sciphi-ai/agent-search/llms.txt Shows how to create a SearchRAGResponse object, which wraps a full RAG search call including the response text, related queries, and search results. Accesses response, related queries, and search results. ```python from agent_search.providers.sciphi import SearchRAGResponse, SearchResult rag = SearchRAGResponse( response="Fermat's Last Theorem states that...", related_queries=["History of Fermat's Last Theorem", "Andrew Wiles proof"], search_results=[ SearchResult( score=0.95, url="https://example.com", title="Fermat", text="...", dataset="wikipedia", metadata={} ) ], ) print(rag.response) print(rag.related_queries[0]) # "History of Fermat's Last Theorem" print(len(rag.search_results)) # 1 ``` -------------------------------- ### Perform Standalone Search with SciPhi.search() Source: https://context7.com/sciphi-ai/agent-search/llms.txt Execute a search query using the `search` method. Specify the search provider ('agent-search' or 'bing') and optionally the number of retries. Results are ranked dictionaries. ```python from agent_search import SciPhi client = SciPhi() # Search using the AgentSearch engine results = client.search( query="Quantum Field Theory", search_provider="agent-search", # or "bing" max_retries=3, ) # Each result is a dict matching the SearchResult model for r in results: print(f"Score: {r['score']:.4f}") print(f"Title: {r['title']}") print(f"URL: {r['url']}") print(f"Text: {r['text'][:200]}") print(f"Dataset: {r['dataset']}") print("-" * 60) # Example output: # Score: 0.9219 # Title: Quantum field theory in curved spacetime # URL: https://en.wikipedia.org/wiki/Quantum%20field%20theory%20in%20curved%20spacetime # Text: These theories rely on general relativity to describe a curved background... # Dataset: wikipedia ``` -------------------------------- ### Query AgentSearch REST API /search_rag Endpoint Source: https://context7.com/sciphi-ai/agent-search/llms.txt Shows how to use the /search_rag REST API endpoint to run the full RAG pipeline server-side. This endpoint searches a provider, injects results into an LLM, and returns a grounded response plus related queries in one round-trip. Ensure the SCIPHI_API_KEY environment variable is set. ```bash export SCIPHI_API_KEY=your_key_here curl -X POST https://api.sciphi.ai/search_rag \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "Explain the Turing Test", "search_provider": "bing", "llm_model": "SciPhi/Sensei-7B-V1", "temperature": 0.2, "top_p": 0.95 }' # Response: # { # "response": "The Turing Test is a measure of a machine's ability to exhibit intelligent behavior...", # "related_queries": [ # "What are the origins of the Turing Test?", # "How does the Turing Test work?", # "Criticisms of the Turing Test" # ], # "search_results": [ { ...see /search response format... } ] # } ``` -------------------------------- ### Generate RAG Response with OpenAI Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/quick_start.md Set your API and OpenAI keys, then generate a RAG response using OpenAI's gpt-3.5-turbo model. ```shell export SCIPHI_API_KEY=MY_SCIPHI_API_KEY export OPENAI_API_KEY=MY_OPENAI_KEY # Use OpenAI `gpt-3.5-turbo` for LLM generation python -m agent_search.scripts.run_rag run --query="What is Fermat's last theorem?" --llm_provider_name=openai --llm_model_name=gpt-3.5-turbo ``` -------------------------------- ### Initialize and Use AgentSearchClient for Search Source: https://context7.com/sciphi-ai/agent-search/llms.txt Initializes a low-level HTTP client for direct interaction with the AgentSearch search endpoint. It returns typed AgentSearchResult Pydantic model instances and allows fine-grained control over result set sizes. ```python from agent_search.core import AgentSearchClient # api_base and auth_token default to env vars SCIPHI_API_BASE and SCIPHI_API_KEY client = AgentSearchClient( api_base="https://api.sciphi.ai", auth_token="your_api_key", ) results = client.search( query="What is a Lagrangian?", limit_broad_results=1000, # initial candidate pool limit_deduped_url_results=100, # after URL deduplication limit_hierarchical_url_results=25, # after hierarchical re-ranking limit_final_pagerank_results=10, # final PageRank-ranked results ) for r in results: print(f"{r.score:.4f} | {r.title} | {r.url}") # 0.9103 | Lagrangian mechanics | https://en.wikipedia.org/wiki/Lagrangian_mechanics # Access full Pydantic model fields print(results[0].text) # document excerpt print(results[0].dataset) # e.g. "wikipedia" print(results[0].metadata) # dict with optional metadata ``` -------------------------------- ### Generate Completion Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/index.md Generates a raw string completion based on a formatted prompt and a specified LLM model. ```APIDOC ## completion ### Description Generates a raw string completion from the specified LLM model based on the provided formatted prompt. ### Method client.completion ### Parameters - **formatted_prompt** (string) - Required - The prompt to use for completion. - **llm_model_name** (string) - Required - The name of the LLM model to use (e.g., "SciPhi/Sensei-7B-V1"). ### Response Example ```json "The completion text from the LLM..." ``` ``` -------------------------------- ### REST API - /search_rag Source: https://context7.com/sciphi-ai/agent-search/llms.txt Runs the full RAG pipeline server-side: searches the specified provider, injects results into the LLM, and returns a grounded response plus related queries in one round-trip. ```APIDOC ## REST API — `/search_rag` Endpoint Runs the full RAG pipeline server-side: searches the specified provider, injects results into the LLM, and returns a grounded response plus related queries in one round-trip. ```bash export SCIPHI_API_KEY=your_key_here curl -X POST https://api.sciphi.ai/search_rag \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "Explain the Turing Test", "search_provider": "bing", "llm_model": "SciPhi/Sensei-7B-V1", "temperature": 0.2, "top_p": 0.95 }' # Response: # { # "response": "The Turing Test is a measure of a machine's ability to exhibit intelligent behavior...", # "related_queries": [ # "What are the origins of the Turing Test?", # "How does the Turing Test work?", # "Criticisms of the Turing Test" # ], # "search_results": [ { ...see /search response format... } ] # } ``` ``` -------------------------------- ### One-Call RAG Search with SciPhi.get_search_rag_response() Source: https://context7.com/sciphi-ai/agent-search/llms.txt Perform a full RAG pipeline with a single API call. This method fetches search results and uses an LLM to generate a grounded response and related queries. Configure the LLM model, temperature, and top_p parameters. ```python from agent_search import SciPhi client = SciPhi() result = client.get_search_rag_response( query="What caused the 2008 financial crisis?", search_provider="bing", # "bing" or "agent-search" llm_model="SciPhi/Sensei-7B-V1", # default temperature=0.2, top_p=0.95, ) print(result["response"]) # "The 2008 financial crisis was primarily caused by..." print(result["related_queries"]) # ["Role of mortgage-backed securities in 2008 crisis", # "Government response to the 2008 financial crisis", ...] print(len(result["search_results"])) # list of SearchResult dicts # 10 ``` -------------------------------- ### LLM Completions Endpoint Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/api/main.md Access the SciPhi Sensei model directly for purposes beyond Search RAG, or with your own search context. This endpoint is compatible with OpenAI's API specification. ```APIDOC ## POST /v1/completions ### Description This endpoint allows direct access to the SciPhi Sensei LLM model for custom applications. It adheres to the OpenAI API specification for compatibility. ### Method POST ### Endpoint https://api.sciphi.ai/v1/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use for completion (e.g., "SciPhi/Sensei-7B-V1"). - **prompt** (string) - Required - The input prompt for the model, potentially including search results or instructions. - **temperature** (number) - Optional - Controls randomness; 0.0 for deterministic output. ### Request Example ```bash export SEARCH_CONTEXT="N/A" export RESPONSE_PREFIX='{"response":' curl https://api.sciphi.ai/v1/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -d '{ \ "model": "SciPhi/Sensei-7B-V1", \ "prompt": "### Instruction:\n\nQuery:\nWhat is the meaning of life?\n\nSearch Results:\n${SEARCH_CONTEXT}\ \nQuery:\nWhat is the meaning of life?\n### Response:\n${RESPONSE_PREFIX}", \ "temperature": 0.0 \ }' ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of the object returned (e.g., "text_completion"). - **created** (integer) - Timestamp of creation. - **model** (string) - The model used for the completion. - **choices** (array) - A list of completion choices. - **index** (integer) - Index of the choice. - **text** (string) - The generated text completion. - **logprobs** (null) - Log probabilities (currently null). - **finish_reason** (string) - The reason the completion finished (e.g., "length"). - **usage** (object) - Token usage statistics. - **prompt_tokens** (integer) - Number of tokens in the prompt. - **total_tokens** (integer) - Total number of tokens used. - **completion_tokens** (integer) - Number of tokens in the completion. #### Response Example ```json { "id":"cmpl-f03f53c15a174ffe89bdfc83507de7a9", "object":"text_completion", "created":389200, "model":"SciPhi/Sensei-7B-V1", "choices":[ { "index":0, "text":"The quest for the meaning of life is a profound and multifaceted in", "logprobs":null, "finish_reason":"length" } ], "usage": { "prompt_tokens":49, "total_tokens":65, "completion_tokens":16 } } ``` ``` -------------------------------- ### Perform a Search RAG Query Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/api/main.md Retrieve a Retrieval-Augmented Generation (RAG) response using specified search provider, LLM model, and generation parameters. Requires setting the SCIPHI_API_KEY environment variable. ```bash export SCIPHI_API_KEY=${MY_API_KEY} curl -X POST https://api.sciphi.ai/search_rag \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "Explain the Turing Test", "search_provider": "bing", "llm_model": "SciPhi/Sensei-7B-V1", "temperature": 0.2, "top_p": 0.95 }' ``` -------------------------------- ### Generate Completion Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/python_client/main.md Generates a text completion based on a given prompt and specified language model parameters. ```APIDOC ## Generate Completion ### Description Generates a completion string for a given prompt using the SciPhi API with configurable language model parameters. ### Method ```python completion = client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") ``` ### Parameters #### completion - **prompt** (str) - Required - The prompt for generating completion. - **llm_model_name** (str) - Optional - The language model to use (defaults to 'SciPhi/Sensei-7B-V1'). - **llm_max_tokens_to_sample** (int) - Optional - Maximum number of tokens for the sample (defaults to 1024). - **llm_temperature** (float) - Optional - The temperature setting for the query (defaults to 0.2). - **llm_top_p** (float) - Optional - The top-p setting for the query (defaults to 0.90). ### Returns - str: A string containing the generated completion. ``` -------------------------------- ### Generate RAG Response with SciPhi SearchAgent Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/setup/quick_start.md Set your API key and generate a RAG response for a given query using the SciPhi SearchAgent. ```shell export SCIPHI_API_KEY=MY_SCIPHI_API_KEY # Use the SciPhi `SearchAgent` for LLM RAG w/ AgentSearch python -m agent_search.scripts.run_rag run --query="What is Fermat's last theorem?" ``` -------------------------------- ### Perform Standalone Search with AgentSearch Source: https://github.com/sciphi-ai/agent-search/blob/main/docs/source/index.md Utilize the SciPhi client to perform a standalone search using the AgentSearch provider. ```python from agent_search import SciPhi client = SciPhi() # Perform a search search_response = client.search(query='Quantum Field Theory', search_provider='agent-search') print(search_response) # [{ 'score': '.89', 'url': 'https://...', 'metadata': {...} } ``` -------------------------------- ### Set SciPhi API Key Environment Variable Source: https://github.com/sciphi-ai/agent-search/blob/main/README.md Set your SciPhi API key as an environment variable. This is required for authentication when using the client. ```bash export SCIPHI_API_KEY=$MY_SCIPHI_API_KEY ``` -------------------------------- ### Instantiate and Use AgentSearchResult Source: https://context7.com/sciphi-ai/agent-search/llms.txt Demonstrates creating an AgentSearchResult, the Pydantic model from the low-level AgentSearchClient. It automatically strips duplicate titles from text and provides a `to_string_dict` method for stringified output. ```python from agent_search.core.search_types import AgentSearchResult result = AgentSearchResult( score=0.89, url="https://arxiv.org/abs/1308.6773", title="Quantum field theory on curved spacetime", dataset="arxiv", metadata={"timestamp": "1995-09-29", "arxiv_id": "gr-qc/9509057"}, text="Quantum field theory on curved spacetime and the standard cosmological model...", ) as_dict = result.to_string_dict() # all values cast to str print(as_dict["score"]) # "0.89" print(as_dict["dataset"]) # "arxiv" ``` -------------------------------- ### SciPhi.get_search_rag_response() Source: https://context7.com/sciphi-ai/agent-search/llms.txt Execute a full RAG pipeline in a single API call. This method fetches search results and uses a specified LLM to generate a grounded response and a list of related follow-up queries. ```APIDOC ## `SciPhi.get_search_rag_response()` — One-Call RAG Search Performs a full RAG pipeline in a single API call: fetches search results and feeds them into the specified LLM to produce a grounded response and a list of related follow-up queries. Returns a `SearchRAGResponse`-shaped dictionary. ```python from agent_search import SciPhi client = SciPhi() result = client.get_search_rag_response( query="What caused the 2008 financial crisis?", search_provider="bing", # "bing" or "agent-search" llm_model="SciPhi/Sensei-7B-V1", # default temperature=0.2, top_p=0.95, ) print(result["response"]) # "The 2008 financial crisis was primarily caused by..." print(result["related_queries"]) # ["Role of mortgage-backed securities in 2008 crisis", # "Government response to the 2008 financial crisis", ...] print(len(result["search_results"])) # list of SearchResult dicts # 10 ``` ```