graph_retriever.testing¶
Helpers for testing Graph Retriever implementations.
adapter_tests ¶
            AdapterComplianceCase
  
      dataclass
  
¶
    
AdapterComplianceSuite ¶
              Bases: ABC
Test suite for adapter compliance.
To use this, create a sub-class containing a @pytest.fixture named
adapter which returns an Adapter with the documents from animals.jsonl
loaded.
adjacent_case ¶
adjacent_case(request) -> AdjacentCase
Fixture providing the get_adjacent and aget_adjacent test cases.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              
            expected ¶
expected(
    method: str, case: AdapterComplianceCase
) -> list[str]
Override to change the expected behavior of a case.
If the test is expected to fail, call pytest.xfail(reason), or
pytest.skip(reason) if it can't be executed.
Generally, this should not change the expected results, unless the the
adapter being tested uses wildly different distance metrics or a
different embedding. The AnimalsEmbedding is deterministic and the
results across vector stores should generally be deterministic and
consistent.
| PARAMETER | DESCRIPTION | 
|---|---|
                method
             | 
            
               The method being tested. For instance,  
                  
                    TYPE:
                        | 
          
                case
             | 
            
               The case being tested. 
                  
                    TYPE:
                        | 
          
| RETURNS | DESCRIPTION | 
|---|---|
                
                    list[str]
                
             | 
            
               The expected animals.  | 
          
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              search_case ¶
search_case(request) -> SearchCase
Fixture providing the (a)?similarity_search_* test cases.
            test_aadjacent
  
      async
  
¶
test_aadjacent(
    adapter: Adapter, adjacent_case: AdjacentCase
) -> None
Run tests for `aadjacent.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              test_adjacent ¶
test_adjacent(
    adapter: Adapter, adjacent_case: AdjacentCase
) -> None
Run tests for `adjacent.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              
            test_aget
  
      async
  
¶
    Run tests for aget.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              
            
            test_asearch
  
      async
  
¶
test_asearch(
    adapter: Adapter, search_case: SearchCase
) -> None
Run tests for asearch.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              
            test_asearch_with_embedding
  
      async
  
¶
test_asearch_with_embedding(
    adapter: Adapter, search_case: SearchCase
) -> None
Run tests for asearch_with_embedding.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              test_get ¶
Run tests for get.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              
            test_search ¶
test_search(
    adapter: Adapter, search_case: SearchCase
) -> None
Run tests for search.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              test_search_with_embedding ¶
test_search_with_embedding(
    adapter: Adapter, search_case: SearchCase
) -> None
Run tests for search_with_embedding.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              
            AdjacentCase
  
      dataclass
  
¶
    
            GetCase
  
      dataclass
  
¶
    
            SearchCase
  
      dataclass
  
¶
SearchCase(
    query: str,
    k: int | None = None,
    filter: dict[str, str] | None = None,
    *,
    id: str,
    expected: list[str],
    requires_nested: bool = False,
    requires_dict_in_list: bool = False,
)
assert_ids_any_order ¶
Assert the results are valid and match the IDs.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              assert_ids_in_cosine_similarity_order ¶
assert_ids_in_cosine_similarity_order(
    results: Iterable[Content],
    expected: list[str],
    query_embedding: list[float],
    adapter: Adapter,
) -> None
Assert the results are valid and in cosine similarity order.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              assert_valid_results ¶
cosine_similarity_scores ¶
cosine_similarity_scores(
    adapter: Adapter,
    query_or_embedding: str | list[float],
    ids: list[str],
) -> dict[str, float]
Return the cosine similarity scores for the given IDs and query embedding.
Source code in packages/graph-retriever/src/graph_retriever/testing/adapter_tests.py
              embeddings ¶
AnimalEmbeddings ¶
              Bases: WordEmbeddings
Embeddings for animal test-case.
Source code in packages/graph-retriever/src/graph_retriever/testing/embeddings.py
                    __call__ ¶
Return the embedding.
ParserEmbeddings ¶
ParserEmbeddings(dimension: int = 10)
Parse the tuext as a list of floats, otherwise return zeros.
Source code in packages/graph-retriever/src/graph_retriever/testing/embeddings.py
                    
                  __call__ ¶
Return the embedding.
Source code in packages/graph-retriever/src/graph_retriever/testing/embeddings.py
              
            WordEmbeddings ¶
Embeddings based on a word list.
Source code in packages/graph-retriever/src/graph_retriever/testing/embeddings.py
                    
                  __call__ ¶
Return the embedding.
angular_2d_embedding ¶
Convert input text to a 'vector' (list of floats).
| PARAMETER | DESCRIPTION | 
|---|---|
                text
             | 
            
               The text to embed. 
                  
                    TYPE:
                        | 
          
| RETURNS | DESCRIPTION | 
|---|---|
                
                    list[float]
                
             | 
            
               If the text is a number, use it as the angle for the unit vector in units of pi. Any other input text becomes the singular result   | 
          
Source code in packages/graph-retriever/src/graph_retriever/testing/embeddings.py
              earth_embeddings ¶
Split words and return a vector based on that.