openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
examples/semanticsearch/README.md
30lines · modeblame
3c6d4cd6Greg Brockman5 years ago | 1 | # semanticsearch |
| 2 | | |
| 3 | A client-side implementation of our semantic search endpoint (https://beta.openai.com/docs/api-reference/search). | |
| 4 | | |
| 5 | Our endpoint has a special fast implementation of this logic which | |
| 6 | makes it very fast for calls involving many documents, so we recommend | |
| 7 | using our implementation rather than this one for latency-sensitive | |
| 8 | workloads. | |
| 9 | | |
| 10 | We encourage you to try different variants of this client-side logic | |
| 11 | -- we don't think our setup is likely optimal at all! | |
| 12 | | |
| 13 | ## Sample usage | |
| 14 | | |
| 15 | The following usage will run a client-side semantic search. This | |
| 16 | formats each document into a prompt asking the API for the document's | |
| 17 | relevance, and then post-processes the logprobs to derive relevance | |
| 18 | scores: | |
| 19 | | |
| 20 | ``` | |
| 21 | $ ./semanticsearch.py -q 'positive emotion' -d happy -d sad | |
| 22 | [client-side semantic search] {'object': 'list', 'data': [{'object': 'search_result', 'document': 0, 'score': 204.448}, {'object': 'search_result', 'document': 1, 'score': 108.208}], 'model': 'ada:2020-05-03'} | |
| 23 | ``` | |
| 24 | | |
| 25 | We run the exact same logic server-side: | |
| 26 | | |
| 27 | ``` | |
| 28 | $ ./semanticsearch.py -q 'positive emotion' -d happy -d sad -s | |
| 29 | [server-side semantic search] {'object': 'list', 'data': [{'object': 'search_result', 'document': 0, 'score': 204.448}, {'object': 'search_result', 'document': 1, 'score': 108.208}], 'model': 'ada:2020-05-03'} | |
| 30 | ``` |